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

Commit 644179c

Browse files
feat: add java solution to lc problem: No.1289.Minimum Falling Path Sum II (doocs#536)
1 parent e390190 commit 644179c

File tree

3 files changed

+66
-2
lines changed

3 files changed

+66
-2
lines changed

‎solution/1200-1299/1289.Minimum Falling Path Sum II/README.md‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,28 @@
5454
<!-- 这里可写当前语言的特殊实现逻辑 -->
5555

5656
```java
57-
57+
class Solution {
58+
public void rotate(int[] nums, int k) {
59+
int[] res = new int[nums.length];
60+
int leftInit = 0;
61+
if (nums.length < k) {
62+
k = k % nums.length;
63+
}
64+
for (int i = nums.length - k; i < nums.length; i++) {
65+
res[leftInit] = nums[i];
66+
leftInit++;
67+
}
68+
int rightInit = 0;
69+
for (int i = k; i < nums.length; i++) {
70+
res[i] = nums[rightInit];
71+
rightInit++;
72+
}
73+
for (int i = 0; i < nums.length; i++) {
74+
nums[i] = res[i];
75+
}
76+
77+
}
78+
}
5879
```
5980

6081
### **...**

‎solution/1200-1299/1289.Minimum Falling Path Sum II/README_EN.md‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,28 @@ The falling path with the smallest sum is&nbsp;[1,5,7], so the answer is&nbsp;13
4444
### **Java**
4545

4646
```java
47-
47+
class Solution {
48+
public void rotate(int[] nums, int k) {
49+
int[] res = new int[nums.length];
50+
int leftInit = 0;
51+
if (nums.length < k) {
52+
k = k % nums.length;
53+
}
54+
for (int i = nums.length - k; i < nums.length; i++) {
55+
res[leftInit] = nums[i];
56+
leftInit++;
57+
}
58+
int rightInit = 0;
59+
for (int i = k; i < nums.length; i++) {
60+
res[i] = nums[rightInit];
61+
rightInit++;
62+
}
63+
for (int i = 0; i < nums.length; i++) {
64+
nums[i] = res[i];
65+
}
66+
67+
}
68+
}
4869
```
4970

5071
### **...**
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
public void rotate(int[] nums, int k) {
3+
int[] res = new int[nums.length];
4+
int leftInit = 0;
5+
if (nums.length < k) {
6+
k = k % nums.length;
7+
}
8+
for (int i = nums.length - k; i < nums.length; i++) {
9+
res[leftInit] = nums[i];
10+
leftInit++;
11+
}
12+
int rightInit = 0;
13+
for (int i = k; i < nums.length; i++) {
14+
res[i] = nums[rightInit];
15+
rightInit++;
16+
}
17+
for (int i = 0; i < nums.length; i++) {
18+
nums[i] = res[i];
19+
}
20+
21+
}
22+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /