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

Commitaedccf6

Browse files
authored
Updated tasks 139-208
1 parent2150e4f commitaedccf6

File tree

17 files changed

+83
-88
lines changed

17 files changed

+83
-88
lines changed

‎README.md‎

Lines changed: 35 additions & 35 deletions
Large diffs are not rendered by default.

‎src/main/java/g0101_0200/s0139_word_break/Solution.java‎

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,36 @@
33
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #String #Hash_Table
44
// #Dynamic_Programming #Trie #Memoization #Algorithm_II_Day_15_Dynamic_Programming
55
// #Dynamic_Programming_I_Day_9 #Udemy_Dynamic_Programming #Big_O_Time_O(M+max*N)_Space_O(M+N+max)
6-
// #2022_06_24_Time_2_ms_(97.08%)_Space_42.1_MB_(90.92%)
6+
// #2024_11_15_Time_1_ms_(99.42%)_Space_42.1_MB_(80.42%)
77

8-
importjava.util.HashSet;
98
importjava.util.List;
10-
importjava.util.Set;
119

1210
publicclassSolution {
11+
privateBoolean[]memo;
12+
1313
publicbooleanwordBreak(Strings,List<String>wordDict) {
14-
Set<String>set =newHashSet<>();
15-
intmax =0;
16-
boolean[]flag =newboolean[s.length() +1];
17-
for (Stringst :wordDict) {
18-
set.add(st);
19-
if (max <st.length()) {
20-
max =st.length();
21-
}
22-
}
23-
for (inti =1;i <=max;i++) {
24-
if (dfs(s,0,i,max,set,flag)) {
25-
returntrue;
26-
}
27-
}
28-
returnfalse;
14+
memo =newBoolean[s.length() +1];
15+
returndp(s,0,wordDict);
2916
}
3017

31-
privatebooleandfs(Strings,intstart,intend,intmax,Set<String>set,boolean[]flag) {
32-
if (!flag[end] &&set.contains(s.substring(start,end))) {
33-
flag[end] =true;
34-
if (end ==s.length()) {
35-
returntrue;
18+
publicbooleandp(Strings,inti,List<String>wordDict) {
19+
if (i ==s.length()) {
20+
returntrue;
21+
}
22+
if (memo[i] !=null) {
23+
returnmemo[i];
24+
}
25+
for (Stringword :wordDict) {
26+
intlen =word.length();
27+
if (i +len >s.length() || !s.substring(i,i +len).equals(word)) {
28+
continue;
3629
}
37-
for (inti =1;i <=max;i++) {
38-
if (end +i <=s.length() &&dfs(s,end,end +i,max,set,flag)) {
39-
returntrue;
40-
}
30+
if (dp(s,i +len,wordDict)) {
31+
memo[i] =true;
32+
returntrue;
4133
}
4234
}
35+
memo[i] =false;
4336
returnfalse;
4437
}
4538
}

‎src/main/java/g0101_0200/s0141_linked_list_cycle/Solution.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Hash_Table #Two_Pointers #Linked_List
44
// #Data_Structure_I_Day_7_Linked_List #Udemy_Linked_List #Big_O_Time_O(N)_Space_O(1)
5-
// #2022_06_24_Time_0_ms_(100.00%)_Space_45.5_MB_(68.52%)
5+
// #2024_11_15_Time_0_ms_(100.00%)_Space_44.3_MB_(52.46%)
66

77
importcom_github_leetcode.ListNode;
88

‎src/main/java/g0101_0200/s0142_linked_list_cycle_ii/Solution.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// #Medium #Top_100_Liked_Questions #Hash_Table #Two_Pointers #Linked_List
44
// #Data_Structure_II_Day_10_Linked_List #Level_1_Day_4_Linked_List #Udemy_Linked_List
5-
// #Big_O_Time_O(N)_Space_O(1) #2022_06_24_Time_0_ms_(100.00%)_Space_42.3_MB_(98.70%)
5+
// #Big_O_Time_O(N)_Space_O(1) #2024_11_15_Time_0_ms_(100.00%)_Space_44.7_MB_(20.31%)
66

77
importcom_github_leetcode.ListNode;
88

‎src/main/java/g0101_0200/s0146_lru_cache/LRUCache.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Hash_Table #Design #Linked_List
44
// #Doubly_Linked_List #Udemy_Linked_List #Big_O_Time_O(1)_Space_O(capacity)
5-
// #2022_06_24_Time_87_ms_(50.80%)_Space_125.2_MB_(58.73%)
5+
// #2024_11_15_Time_40_ms_(98.20%)_Space_111.4_MB_(88.70%)
66

77
importjava.util.HashMap;
88
importjava.util.Map;

‎src/main/java/g0101_0200/s0148_sort_list/Solution.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Sorting #Two_Pointers #Linked_List
44
// #Divide_and_Conquer #Merge_Sort #Level_2_Day_4_Linked_List #Big_O_Time_O(log(N))_Space_O(log(N))
5-
// #2022_06_24_Time_12_ms_(85.82%)_Space_76_MB_(43.84%)
5+
// #2024_11_15_Time_9_ms_(93.90%)_Space_56.9_MB_(37.47%)
66

77
importcom_github_leetcode.ListNode;
88

‎src/main/java/g0101_0200/s0152_maximum_product_subarray/Solution.java‎

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,24 @@
22

33
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Dynamic_Programming
44
// #Dynamic_Programming_I_Day_6 #Level_2_Day_13_Dynamic_Programming #Udemy_Dynamic_Programming
5-
// #Big_O_Time_O(N)_Space_O(1) #2024_07_03_Time_1_ms_(92.31%)_Space_44.6_MB_(75.65%)
5+
// #Big_O_Time_O(N)_Space_O(1) #2024_11_15_Time_1_ms_(92.74%)_Space_45_MB_(23.41%)
66

77
publicclassSolution {
88
publicintmaxProduct(int[]nums) {
9-
intcurrentMaxProd =nums[0];
10-
intcurrentMinProd =nums[0];
11-
intoverAllMaxProd =nums[0];
12-
for (inti =1;i <nums.length;i++) {
13-
if (nums[i] <0) {
14-
inttemp =currentMaxProd;
15-
currentMaxProd =currentMinProd;
16-
currentMinProd =temp;
9+
intoverAllMaxProd =Integer.MIN_VALUE;
10+
intn =nums.length;
11+
intstart =1;
12+
intend =1;
13+
for (inti =0;i <n;i++) {
14+
if (start ==0) {
15+
start =1;
1716
}
18-
currentMaxProd =Math.max(nums[i],nums[i] *currentMaxProd);
19-
currentMinProd =Math.min(nums[i],nums[i] *currentMinProd);
20-
overAllMaxProd =Math.max(overAllMaxProd,currentMaxProd);
17+
if (end ==0) {
18+
end =1;
19+
}
20+
start =start *nums[i];
21+
end =end *nums[n -i -1];
22+
overAllMaxProd =Math.max(overAllMaxProd,Math.max(start,end));
2123
}
2224
returnoverAllMaxProd;
2325
}

‎src/main/java/g0101_0200/s0153_find_minimum_in_rotated_sorted_array/Solution.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// #Medium #Top_100_Liked_Questions #Array #Binary_Search #Algorithm_II_Day_2_Binary_Search
44
// #Binary_Search_I_Day_12 #Udemy_Binary_Search #Big_O_Time_O(log_N)_Space_O(log_N)
5-
// #2022_06_25_Time_0_ms_(100.00%)_Space_43.3_MB_(6.36%)
5+
// #2024_11_15_Time_0_ms_(100.00%)_Space_42.1_MB_(33.31%)
66

77
publicclassSolution {
88
privateintfindMinUtil(int[]nums,intl,intr) {

‎src/main/java/g0101_0200/s0155_min_stack/MinStack.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Stack #Design
44
// #Data_Structure_II_Day_14_Stack_Queue #Programming_Skills_II_Day_18 #Level_2_Day_16_Design
5-
// #Udemy_Design #Big_O_Time_O(1)_Space_O(N) #2022_06_25_Time_3_ms_(100.00%)_Space_44.3_MB_(85.39%)
5+
// #Udemy_Design #Big_O_Time_O(1)_Space_O(N) #2024_11_15_Time_4_ms_(96.54%)_Space_44.5_MB_(84.54%)
66

77
publicclassMinStack {
88
privatestaticclassNode {

‎src/main/java/g0101_0200/s0160_intersection_of_two_linked_lists/Solution.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Hash_Table #Two_Pointers #Linked_List
44
// #Data_Structure_II_Day_11_Linked_List #Udemy_Linked_List #Big_O_Time_O(M+N)_Space_O(1)
5-
// #2022_06_25_Time_1_ms_(99.68%)_Space_55.1_MB_(63.42%)
5+
// #2024_11_15_Time_1_ms_(99.92%)_Space_48.4_MB_(68.45%)
66

77
importcom_github_leetcode.ListNode;
88

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp