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

Commitc365dec

Browse files
add 1641
1 parentb98de6c commitc365dec

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ _If you like this project, please leave me a star._ ★
3434
|1656|[Design an Ordered Stream](https://leetcode.com/problems/design-an-ordered-stream/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1656.java)||Easy|Array, Design|
3535
|1652|[Defuse the Bomb](https://leetcode.com/problems/defuse-the-bomb/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1652.java)||Easy|Array|
3636
|1646|[Get Maximum in Generated Array](https://leetcode.com/problems/get-maximum-in-generated-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1646.java)||Easy|Array|
37+
|1641|[Count Sorted Vowel Strings](https://leetcode.com/problems/count-sorted-vowel-strings/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1641.java)||Medium|Math, DP, Backtracking|
3738
|1640|[Check Array Formation Through Concatenation](https://leetcode.com/problems/check-array-formation-through-concatenation/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1640.java)||Easy|Array, Sort|
3839
|1637|[Widest Vertical Area Between Two Points Containing No Points](https://leetcode.com/problems/widest-vertical-area-between-two-points-containing-no-points/)|[Javascript](./javascript/_1637.js)|| Medium| Sort|
3940
|1636|[Sort Array by Increasing Frequency](https://leetcode.com/problems/sort-array-by-increasing-frequency/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1636.java)||Easy|Array, Sort|
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
packagecom.fishercoder.solutions;
2+
3+
importjava.util.Arrays;
4+
5+
publicclass_1641 {
6+
publicstaticclassSolution1 {
7+
/**
8+
* I solved this problem using Math, no DP, recursion or backtracking techniques.
9+
* Time: beat 100% submission consistently since it's O(n), essentialy it's O(1) because the contraints in the problem state: 1 <= n <= 50
10+
* After writing out from n = 1 to 3, we can see the pattern.
11+
* Detailed reasoning to be seen in my youtube video on my channel: https://www.youtube.com/fishercoder.
12+
*/
13+
publicintcountVowelStrings(intn) {
14+
if (n ==1) {
15+
return5;
16+
}
17+
int[]arr =newint[]{1,1,1,1,1};
18+
intsum =5;
19+
for (inti =2;i <=n;i++) {
20+
int[]copy =newint[5];
21+
for (intj =0;j <arr.length;j++) {
22+
if (j ==0) {
23+
copy[j] =sum;
24+
}else {
25+
copy[j] =copy[j -1] -arr[j -1];
26+
}
27+
}
28+
arr =Arrays.copyOf(copy,5);
29+
sum =0;
30+
for (intj =0;j <arr.length;j++) {
31+
sum +=arr[j];
32+
}
33+
}
34+
sum =0;
35+
for (intj =0;j <arr.length;j++) {
36+
sum +=arr[j];
37+
}
38+
returnsum;
39+
}
40+
}
41+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.solutions._1641;
4+
importorg.junit.BeforeClass;
5+
importorg.junit.Test;
6+
7+
importstaticorg.junit.Assert.assertEquals;
8+
9+
publicclass_1641Test {
10+
privatestatic_1641.Solution1solution1;
11+
12+
@BeforeClass
13+
publicstaticvoidsetup() {
14+
solution1 =new_1641.Solution1();
15+
}
16+
17+
@Test
18+
publicvoidtest1() {
19+
assertEquals(5,solution1.countVowelStrings(1));
20+
}
21+
22+
@Test
23+
publicvoidtest2() {
24+
assertEquals(15,solution1.countVowelStrings(2));
25+
}
26+
27+
@Test
28+
publicvoidtest3() {
29+
assertEquals(35,solution1.countVowelStrings(3));
30+
}
31+
32+
@Test
33+
publicvoidtest4() {
34+
assertEquals(70,solution1.countVowelStrings(4));
35+
}
36+
37+
@Test
38+
publicvoidtest5() {
39+
assertEquals(66045,solution1.countVowelStrings(33));
40+
}
41+
42+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp