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

Commit9ee0585

Browse files
authored
Improved tasks 133, 194, 1022, 2366
1 parent9ddda61 commit9ee0585

File tree

6 files changed

+42
-42
lines changed

6 files changed

+42
-42
lines changed

‎README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,7 @@ implementation 'com.github.javadev:leetcode-in-java:1.43'
11881188
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
11891189
|-|-|-|-|-|-
11901190
| 0200 |[Number of Islands](src/main/java/g0101_0200/s0200_number_of_islands/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find, Big_O_Time_O(M\*N)_Space_O(M\*N) | 3 | 87.24
1191-
| 0133 |[Clone Graph](src/main/java/g0101_0200/s0133_clone_graph/Solution.java)| Medium | Hash_Table, Depth_First_Search, Breadth_First_Search, Graph |45 |29.80
1191+
| 0133 |[Clone Graph](src/main/java/g0101_0200/s0133_clone_graph/Solution.java)| Medium | Hash_Table, Depth_First_Search, Breadth_First_Search, Graph |25 |68.87
11921192
| 0417 |[Pacific Atlantic Water Flow](src/main/java/g0401_0500/s0417_pacific_atlantic_water_flow/Solution.java)| Medium | Array, Depth_First_Search, Breadth_First_Search, Matrix | 5 | 92.62
11931193

11941194
####Udemy Dynamic Programming
@@ -1392,7 +1392,7 @@ implementation 'com.github.javadev:leetcode-in-java:1.43'
13921392
|-|-|-|-|-|-
13931393
| 0200 |[Number of Islands](src/main/java/g0101_0200/s0200_number_of_islands/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find, Big_O_Time_O(M\*N)_Space_O(M\*N) | 3 | 87.24
13941394
| 0130 |[Surrounded Regions](src/main/java/g0101_0200/s0130_surrounded_regions/Solution.java)| Medium | Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find | 2 | 84.66
1395-
| 0133 |[Clone Graph](src/main/java/g0101_0200/s0133_clone_graph/Solution.java)| Medium | Hash_Table, Depth_First_Search, Breadth_First_Search, Graph |45 |29.80
1395+
| 0133 |[Clone Graph](src/main/java/g0101_0200/s0133_clone_graph/Solution.java)| Medium | Hash_Table, Depth_First_Search, Breadth_First_Search, Graph |25 |68.87
13961396
| 0399 |[Evaluate Division](src/main/java/g0301_0400/s0399_evaluate_division/Solution.java)| Medium | Array, Depth_First_Search, Breadth_First_Search, Graph, Union_Find, Shortest_Path, LeetCode_75_Graphs/DFS | 1 | 99.52
13971397
| 0207 |[Course Schedule](src/main/java/g0201_0300/s0207_course_schedule/Solution.java)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Graph, Topological_Sort, Big_O_Time_O(N)_Space_O(N) | 3 | 99.99
13981398
| 0210 |[Course Schedule II](src/main/java/g0201_0300/s0210_course_schedule_ii/Solution.java)| Medium | Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Graph, Topological_Sort | 4 | 91.07

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
packageg0101_0200.s0133_clone_graph;
22

33
// #Medium #Hash_Table #Depth_First_Search #Breadth_First_Search #Graph #Udemy_Graph
4-
// #Top_Interview_150_Graph_General #2022_06_24_Time_45_ms_(29.80%)_Space_42.7_MB_(77.96%)
4+
// #Top_Interview_150_Graph_General #2025_05_03_Time_25_ms_(68.87%)_Space_43.26_MB_(7.02%)
55

66
importcom_github_leetcode.Node;
77
importjava.util.ArrayList;
Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
# Read from the file file.txt and print its transposed content to stdout.
2-
# #Medium #Shell #2022_06_28_Time_630_ms_(28.43%)_Space_3.9_MB_(71.08%)
3-
wordcount=$(head -1 file.txt| wc -w)
4-
col_n=1
5-
while [[$col_n-le$wordcount ]];do
6-
awk"{ print\$$col_n }" file.txt| paste -sd""
7-
col_n=$((col_n+1))
8-
done
2+
# #Medium #Shell #2025_05_03_Time_61_ms_(88.19%)_Space_4.14_MB_(38.67%)
3+
awk'
4+
{
5+
for (i = 1; i <= NF; i++) {
6+
if (NR == 1) {
7+
a[i] = $i
8+
} else {
9+
a[i] = a[i] " " $i
10+
}
11+
}
12+
}
13+
END {
14+
for (i = 1; i <= NF; i++) {
15+
print a[i]
16+
}
17+
}' file.txt
Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
packageg1001_1100.s1022_sum_of_root_to_leaf_binary_numbers;
22

3-
// #Easy #Depth_First_Search #Tree #Binary_Tree #2022_02_26_Time_3_ms_(28.58%)_Space_43.6_MB_(5.47%)
3+
// #Easy #Depth_First_Search #Tree #Binary_Tree
4+
// #2025_05_03_Time_0_ms_(100.00%)_Space_42.08_MB_(64.36%)
45

56
importcom_github_leetcode.TreeNode;
6-
importjava.util.ArrayList;
7-
importjava.util.List;
87

98
/*
109
* Definition for a binary tree node.
@@ -23,31 +22,17 @@
2322
*/
2423
publicclassSolution {
2524
publicintsumRootToLeaf(TreeNoderoot) {
26-
List<List<Integer>>paths =newArrayList<>();
27-
dfs(root,paths,newArrayList<>());
28-
intsum =0;
29-
for (List<Integer>list :paths) {
30-
intnum =0;
31-
for (inti :list) {
32-
num = (num <<1) +i;
33-
}
34-
sum +=num;
35-
}
36-
returnsum;
25+
returnsumRootToLeaf(root,0);
3726
}
3827

39-
privatevoiddfs(TreeNoderoot,List<List<Integer>>paths,List<Integer>path) {
40-
path.add(root.val);
41-
if (root.left !=null) {
42-
dfs(root.left,paths,path);
43-
path.remove(path.size() -1);
44-
}
45-
if (root.right !=null) {
46-
dfs(root.right,paths,path);
47-
path.remove(path.size() -1);
28+
privateintsumRootToLeaf(TreeNoderoot,intsum) {
29+
if (root ==null) {
30+
return0;
4831
}
32+
sum =2 *sum +root.val;
4933
if (root.left ==null &&root.right ==null) {
50-
paths.add(newArrayList<>(path));
34+
returnsum;
5135
}
36+
returnsumRootToLeaf(root.left,sum) +sumRootToLeaf(root.right,sum);
5237
}
5338
}

‎src/main/java/g2301_2400/s2366_minimum_replacements_to_sort_the_array/Solution.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
packageg2301_2400.s2366_minimum_replacements_to_sort_the_array;
22

3-
// #Hard #Array #Math #Greedy #2022_08_14_Time_10_ms_(28.57%)_Space_81.5_MB_(28.57%)
3+
// #Hard #Array #Math #Greedy #2025_05_03_Time_3_ms_(98.58%)_Space_56.46_MB_(8.49%)
44

55
publicclassSolution {
66
publiclongminimumReplacement(int[]nums) {
7-
intlimit =nums[nums.length -1];
7+
intn =nums.length;
8+
intprev =nums[n -1];
89
longans =0;
9-
for (inti =nums.length -2;i >=0;i--) {
10-
intreplacements =nums[i] /limit -1;
11-
if (nums[i] %limit !=0) {
12-
replacements++;
10+
for (inti =n -2;i >=0;i--) {
11+
intnoOfTime =nums[i] /prev;
12+
if (nums[i] %prev !=0) {
13+
noOfTime++;
14+
prev =nums[i] /noOfTime;
1315
}
14-
ans +=replacements;
15-
limit =nums[i] / (replacements +1);
16+
ans +=noOfTime -1;
1617
}
1718
returnans;
1819
}

‎src/test/java/g1001_1100/s1022_sum_of_root_to_leaf_binary_numbers/SolutionTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,9 @@ void sumRootToLeaf2() {
2020
TreeNoderoot =TreeNode.create(Collections.singletonList(0));
2121
assertThat(newSolution().sumRootToLeaf(root),equalTo(0));
2222
}
23+
24+
@Test
25+
voidsumRootToLeaf3() {
26+
assertThat(newSolution().sumRootToLeaf(null),equalTo(0));
27+
}
2328
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp