我正在做leetcode练习
https://leetcode.com/problems/remove-duplicate-letters/ https://leetcode.com/problems/remove-duplicate-letters/
问题是:
# Given a string which contains only lowercase letters, remove duplicate
# letters so that every letter appear once and only once. You must make
# sure your result is the smallest in lexicographical order among all possible results.
#
# Example:
# Given "bcabc"
# Return "abc"
#
# Given "cbacdcbc"
# Return "acdb"
我不太确定what is the smallest in lexicographical order
以及为什么给定“cbacdcbc”那么答案将是“acdb”
感谢您提前的答复:)
The smallest lexicographical order is an order relation where string s is smaller than t, given the first character of s (s1) is smaller than the first character of t (t1), or in case they are equivalent, the second character, etc.
So aaabbb
小于aaac
因为虽然前三个字符相等,但第四个字符b
小于第四个字符c
.
For cbacdcbc
,有多种选择,因为b
and c
是重复项,您可以决定删除哪些重复项。这导致:
cbacdcbc = adbc
cbacdcbc = adcb
cbacdcbc = badc
cbacdcbc = badc
...
since adbc
< adcb
,因此你不能简单地回答你脑海中出现的第一个答案。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)