We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3c538f9 commit 18a8af4Copy full SHA for 18a8af4
String/320.Generalized-Abbreviation/320.Generalized-Abbreviation.cpp
@@ -0,0 +1,29 @@
1
+class Solution {
2
+public:
3
+ vector<string> generateAbbreviations(string word)
4
+ {
5
+ int n = word.size();
6
+ vector<string>rets;
7
+ for (int state = 0; state < (1<<n); state++)
8
9
+ string s;
10
+ for (int i=0; i<n; i++)
11
12
+ if ((state>>i)&1)
13
14
+ s.push_back(word[i]);
15
+ }
16
+ else
17
18
+ int j = i;
19
+ while (j<n && ((state>>j)&1)==0)
20
+ j++;
21
+ s += to_string(j-i);
22
+ i = j-1;
23
24
25
+ rets.push_back(s);
26
27
+ return rets;
28
29
+};
0 commit comments