Myntra编码问题! ! [英] Myntra coding question ! !

查看:129
本文介绍了Myntra编码问题! !的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

爱丽丝必须从家里去上班。他发现它不知怎的第一天并记下它。在办公室里,她找到了更长的路径并缩短了它。



给出一长串路径,缩短它。结果必须按字典顺序排序。



示例: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 -> ES

What 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆