Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcb0df72

Browse files
authored
added solution and test case for 809 (fishercoder1534#149)
1 parente8c75f4 commitcb0df72

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ _If you like this project, please leave me a star._ ★
385385
|819|[Most Common Word](https://leetcode.com/problems/most-common-word/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_819.java) | |Easy| HashMap
386386
|814|[Binary Tree Pruning](https://leetcode.com/problems/binary-tree-pruning/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_814.java) | |Medium| recursion, DFS
387387
|811|[Subdomain Visit Count](https://leetcode.com/problems/subdomain-visit-count/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_811.java) | |Easy| HashMap
388+
|809|[Expressive Words](https://leetcode.com/problems/expressive-words/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_809.java)||Medium|
388389
|807|[Max Increase to Keep City Skyline](https://leetcode.com/problems/max-increase-to-keep-city-skyline/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_807.java)||Medium|
389390
|806|[Number of Lines To Write String](https://leetcode.com/problems/number-of-lines-to-write-string/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_806.java)||Easy|
390391
|804|[Unique Morse Code Words](https://leetcode.com/problems/unique-morse-code-words/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_804.java)||Easy|
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
packagecom.fishercoder.solutions;
2+
3+
publicclass_809 {
4+
publicstaticclassSolution1 {
5+
publicintexpressiveWords (StringS,String[]words ) {
6+
intans =0;
7+
for (Stringw :words) {
8+
if (check(S,w)) {
9+
ans++;
10+
}
11+
}
12+
returnans;
13+
}
14+
privatebooleancheck (StringS,Stringw) {
15+
inti =0;
16+
intj =0;
17+
/* Logic is to check whether character at same index of S and w are same
18+
if same,
19+
1. Find the consecutive number of occurrences of the char in S (say len1) and w ( say len2)
20+
2. If len1 == len 2 , move to the next char in S and w
21+
3. If len1 >= 3 and len2 < len1, means we can make the char in w stretchy to match len1
22+
4. else, return false, because it's not possible to stretch the char in w
23+
*/
24+
while (i <S.length() &&j <w.length()) {
25+
charch1 =S.charAt(i);
26+
charch2 =w.charAt(j);
27+
28+
intlen1 =getLen(S,i);
29+
intlen2 =getLen(w,j);
30+
if (ch1 ==ch2) {
31+
if (len1 ==len2) {
32+
i =i +len1;
33+
j =j +len2;
34+
}
35+
elseif (len1 >=3 &&len2 <len1) {
36+
i =i +len1;
37+
j =j +len2;
38+
}
39+
else {
40+
returnfalse;
41+
}
42+
}
43+
else {
44+
returnfalse;
45+
}
46+
}
47+
returni ==S.length() &&j ==w.length();
48+
}
49+
50+
privateintgetLen (Stringvalue,inti) {
51+
i =i +1;
52+
intcount =1;
53+
for(intj =i;j<value.length();j++) {
54+
if(value.charAt(j) ==value.charAt(i-1)) {
55+
count++;
56+
}
57+
else {
58+
break;
59+
}
60+
}
61+
returncount;
62+
}
63+
}
64+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.solutions._809;
4+
importorg.junit.BeforeClass;
5+
importorg.junit.Test;
6+
7+
importstaticjunit.framework.TestCase.assertEquals;
8+
9+
publicclass_809Test {
10+
privatestatic_809.Solution1solution1;
11+
privateString[]words;
12+
privateStringS;
13+
14+
@BeforeClass
15+
publicstaticvoidsetup() {
16+
solution1 =new_809.Solution1();
17+
}
18+
19+
@Test
20+
publicvoidtest1() {
21+
words =newString[] {"hello","hi","helo"};
22+
S ="heeellooo";
23+
assertEquals(1,solution1.expressiveWords(S,words));
24+
}
25+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp