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

Update _66.java#37

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fishercoder1534 merged 1 commit intofishercoder1534:masterfromjianguda:patch-2
Mar 4, 2019
Merged
Changes fromall 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
45 changes: 17 additions & 28 deletionssrc/main/java/com/fishercoder/solutions/_66.java
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,35 +10,24 @@ public class _66 {

public static class Solution1 {
public int[] plusOne(int[] digits) {
boolean carry = false;
int len = digits.length;
int[] temp = digits;
//process the last digit at first, to get carry value
if (digits[len - 1] + 1 == 10) {
carry = true;
temp[len - 1] = 0;
} else {
temp[len - 1] += 1;
return temp;
}

//start from the second last element
for (int i = len - 2; i >= 0; i--) {
if (carry && temp[i] + 1 == 10) {
temp[i] = 0;
carry = true;
} else if (carry) {
temp[i] += 1;
carry = false;
int len = digits.length;
int[] temp = digits;

for (int i = len - 1; i >= 0; i--) {
if (temp[i] + 1 == 10) {
temp[i] = 0;
} else {
temp[i] += 1;
return temp;
}
}
if (temp[0] == 0) {
int[] res = new int[len + 1];
res[0] = 1; //all the rest of the numbers should all be zeroes, so we don't need to copy from the original array
return res;
} else {
return temp;
}
}
if (carry && temp[0] == 0) {
int[] res = new int[len + 1];
res[0] = 1;
//all the rest of the numbers should all be zeroes, so we don't need to copy from the original array
return res;
}
return temp;
}
}
}

[8]ページ先頭

©2009-2025 Movatter.jp