Myntra编码问题! ! [英] Myntra coding question ! !
问题描述
给出一长串路径,缩短它。结果必须按字典顺序排序。
示例:SSNE简化为ES
S代表南,N为北,W为西,E为东。
我尝试过:
我想删除一起出现的所有相同字符,只保留其中一个字符。
例如:
SSSNNEW - > SNEW - > ENSW(答案)
后来用词典排序字符串。这是正确的方法??
没有。看一下这个例子:
SSNE - > ES你需要做的是删除对立面:北方和南方对,以及东方和西方对。当你删除了对时,你可以排序。
引用:我想删除所有相同的字符一起出现并只保留其中一个。
错误
原则是 N 和 S 是相反的方向, E 和 W 相同。
这意味着如果你有两个;移动 S 将取消移动 N ,与 E 和 W 相同。
所以SS SN NEW - > S b SN EW - > S- >小号
Alice has to go to work from his home. He finds it somehow the first day and keeps a note of it . In the office she finds the path to be longer and shortens it.
Given a string of the long path, shorten it. The result must be sorted lexicographically .
Example : SSNE to be simplified as ES
S stands for South, N for North, W for west , E for east.
What I have tried:
I'am thinking to delete all the same characters which occur together and keep only one of them.
eg:
SSSNNEW -> SNEW -> ENSW(Answer)
and later sort the string lexographically. Is it the right way ??
No. Look at the example:
SSNE -> ESWhat you need to do is remove opposites: A North and a South pair, and East and West pair. When you have removed pairs, you can sort.
Quote:I'am thinking to delete all the same characters which occur together and keep only one of them.
Wrong
the principle is that N and S are opposite directions, same for E and W.
It means that if you have both; a move S will cancel a move N, same with E and W.
So SSSNNEW -> SSNEW -> SEW -> S
这篇关于Myntra编码问题! !的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!