按顺序排列字符串的所有可能的缩写
我从我的朋友那里看到了这个问题。给定一个字符串,生成这些字符的所有可能的缩写,使得这些缩写的字符顺序与原始字符的顺序相同。
例如。对于“abc”,有效的缩写是 a,b,c,ab,ac,bc,abc
我一直在尝试为这个问题想出一个简单的解决方案,到目前为止没有运气。任何线索将不胜感激。
谢谢
I came across this question from my friend. Given a string of characters, generate all possible abbreviations of those characters such that these abbreviations have the characters sequenced in the same order as the original.
For eg. for "abc", valid abbreviations would be a,b,c,ab,ac,bc,abc
I have been trying to come up with a simple solution to this problem, so far no luck. Any lead would be appreciated.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果它可以帮助某人提出解决方案,可以使用二进制掩码来完成,每个字符一位数字。所以对于“abc”,有 2 x 2 x 2 种可能性。 000 - 111。将变量从 000 增加到 111,然后删除有零的字符,留下有效选项列表。
In case it helps someone come up with a solution, it could be done with a binary mask, one digit per character. So for "abc", there are 2 x 2 x 2 possibilities. 000 - 111. Incrementing a variable from 000 to 111, then removing a character where there's a zero, leaves a list of the valid options.