Skip to content

Commit 181cb74

Browse files
authored
Update 411.Minimum-Unique-Word-Abbreviation.cpp
1 parent 7376f61 commit 181cb74

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

String/411.Minimum-Unique-Word-Abbreviation/411.Minimum-Unique-Word-Abbreviation.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Solution {
2424
int mask = masks[i].second;
2525
string a = abbr(target,mask);
2626
int flag = 1;
27-
27+
2828
for (auto word:Set)
2929
{
3030
string b = abbr(word, mask);
@@ -36,6 +36,7 @@ class Solution {
3636
}
3737
if (flag == 1) return a;
3838
}
39+
return "";
3940
}
4041

4142

@@ -44,12 +45,12 @@ class Solution {
4445
int count = 0;
4546
for (int i=0; i<N; i++)
4647
{
47-
if (((mask>>(N-1-i))&1)==1)
48+
if (((mask>>i)&1)==1)
4849
count++;
4950
else
5051
{
5152
int j = i+1;
52-
while (j<N && ((mask>>(N-1-j))&1)==0)
53+
while (j<N && ((mask>>j)&1)==0)
5354
j++;
5455
count++;
5556
i = j-1;
@@ -65,12 +66,12 @@ class Solution {
6566

6667
for (int i=0; i<N; i++)
6768
{
68-
if (((mask>>(N-1-i))&1)==1)
69+
if (((mask>>i)&1)==1)
6970
result.push_back(A[i]);
7071
else
7172
{
7273
int j = i+1;
73-
while (j<N && ((mask>>(N-1-j))&1)==0)
74+
while (j<N && ((mask>>j)&1)==0)
7475
j++;
7576
result += to_string(j-i);
7677
i = j-1;

0 commit comments

Comments
 (0)