File tree 2 files changed +12
-15
lines changed
main/java/com/fishercoder/solutions
test/java/com/fishercoder
2 files changed +12
-15
lines changed Original file line number Diff line number Diff line change 2
2
3
3
public class _809 {
4
4
public static class Solution1 {
5
- public int expressiveWords (String S , String [] words ) {
5
+ public int expressiveWords (String S , String [] words ) {
6
6
int ans = 0 ;
7
7
for (String w : words ) {
8
8
if (check (S , w )) {
@@ -11,7 +11,8 @@ public int expressiveWords (String S, String[] words ) {
11
11
}
12
12
return ans ;
13
13
}
14
- private boolean check (String S , String w ) {
14
+
15
+ private boolean check (String S , String w ) {
15
16
int i = 0 ;
16
17
int j = 0 ;
17
18
/* Logic is to check whether character at same index of S and w are same
@@ -24,37 +25,33 @@ private boolean check (String S, String w) {
24
25
while (i < S .length () && j < w .length ()) {
25
26
char ch1 = S .charAt (i );
26
27
char ch2 = w .charAt (j );
27
-
28
+
28
29
int len1 = getLen (S , i );
29
30
int len2 = getLen (w , j );
30
31
if (ch1 == ch2 ) {
31
32
if (len1 == len2 ) {
32
33
i = i + len1 ;
33
34
j = j + len2 ;
34
- }
35
- else if (len1 >= 3 && len2 < len1 ) {
35
+ } else if (len1 >= 3 && len2 < len1 ) {
36
36
i = i + len1 ;
37
37
j = j + len2 ;
38
- }
39
- else {
38
+ } else {
40
39
return false ;
41
40
}
42
- }
43
- else {
41
+ } else {
44
42
return false ;
45
43
}
46
44
}
47
45
return i == S .length () && j == w .length ();
48
46
}
49
47
50
- private int getLen (String value , int i ) {
48
+ private int getLen (String value , int i ) {
51
49
i = i + 1 ;
52
50
int count = 1 ;
53
- for (int j = i ; j < value .length (); j ++) {
54
- if (value .charAt (j ) == value .charAt (i - 1 )) {
51
+ for (int j = i ; j < value .length (); j ++) {
52
+ if (value .charAt (j ) == value .charAt (i - 1 )) {
55
53
count ++;
56
- }
57
- else {
54
+ } else {
58
55
break ;
59
56
}
60
57
}
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ public static void setup() {
18
18
19
19
@ Test
20
20
public void test1 () {
21
- words = new String [] {"hello" , "hi" , "helo" };
21
+ words = new String []{"hello" , "hi" , "helo" };
22
22
S = "heeellooo" ;
23
23
assertEquals (1 , solution1 .expressiveWords (S , words ));
24
24
}
You can’t perform that action at this time.
0 commit comments