Skip to content

feat: add java solution to lc problem: No.1289.Minimum Falling Path Sum Ⅱ #536

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion solution/1200-1299/1289.Minimum Falling Path Sum II/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,28 @@
<!-- 这里可写当前语言的特殊实现逻辑 -->

```java

class Solution {
public void rotate(int[] nums, int k) {
int[] res = new int[nums.length];
int leftInit = 0;
if (nums.length < k) {
k = k % nums.length;
}
for (int i = nums.length - k; i < nums.length; i++) {
res[leftInit] = nums[i];
leftInit++;
}
int rightInit = 0;
for (int i = k; i < nums.length; i++) {
res[i] = nums[rightInit];
rightInit++;
}
for (int i = 0; i < nums.length; i++) {
nums[i] = res[i];
}

}
}
```

### **...**
Expand Down
23 changes: 22 additions & 1 deletion solution/1200-1299/1289.Minimum Falling Path Sum II/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,28 @@ The falling path with the smallest sum is&nbsp;[1,5,7], so the answer is&nbsp;13
### **Java**

```java

class Solution {
public void rotate(int[] nums, int k) {
int[] res = new int[nums.length];
int leftInit = 0;
if (nums.length < k) {
k = k % nums.length;
}
for (int i = nums.length - k; i < nums.length; i++) {
res[leftInit] = nums[i];
leftInit++;
}
int rightInit = 0;
for (int i = k; i < nums.length; i++) {
res[i] = nums[rightInit];
rightInit++;
}
for (int i = 0; i < nums.length; i++) {
nums[i] = res[i];
}

}
}
```

### **...**
Expand Down
22 changes: 22 additions & 0 deletions solution/1200-1299/1289.Minimum Falling Path Sum II/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Solution {
public void rotate(int[] nums, int k) {
int[] res = new int[nums.length];
int leftInit = 0;
if (nums.length < k) {
k = k % nums.length;
}
for (int i = nums.length - k; i < nums.length; i++) {
res[leftInit] = nums[i];
leftInit++;
}
int rightInit = 0;
for (int i = k; i < nums.length; i++) {
res[i] = nums[rightInit];
rightInit++;
}
for (int i = 0; i < nums.length; i++) {
nums[i] = res[i];
}

}
}