-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringCompression
More file actions
57 lines (53 loc) · 1.49 KB
/
StringCompression
File metadata and controls
57 lines (53 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// https://leetcode.com/contest/weekly-contest-78/problems/expressive-words/
class Solution {
public:
int expressiveWords(string S, vector<string>& words) {
int total = 0;
for(int i=0; i<words.size(); i++)
{
string query = words[i];
int sptr = 0;
int qptr = 0;
char prev;
int qrep = 0;
bool exten = false;
while(sptr<S.length())
{
if(exten == true && qrep < 3 && S[sptr] != prev)
{
break;
}
if(qptr<query.length() && S[sptr] == query[qptr])
{
if(sptr == 0 || S[sptr]!=prev)
{
qrep = 0;
exten = false;
}
prev = query[qptr];
sptr ++;
qptr ++;
qrep ++;
}
else
{
if(S[sptr] == prev)
{
exten = true;
sptr++;
qrep++;
}
else
{
break;
}
}
}
if(sptr == S.length() && qptr == query.length())
{
total ++;
}
}
return total;
}
};