all possible abbreviations of a string in order
I came across th开发者_运维百科is 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
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.
精彩评论