• 문제 링크
Plus One - LeetCode
Can you solve this real interview question? Plus One - You are given a large integer represented as an integer array digits, where each digits[i] is the ith digit of the integer. The digits are ordered from most significant to least significant in left-to-
leetcode.com
• 풀이 코드
public class Solution {
public int[] plusOne(int[] digits) {
for (int i = digits.length - 1; i >= 0; digits[i--] = 0) {
if (digits[i] < 9) {
digits[i]++;
return digits;
}
}
int[] arr = new int[digits.length + 1];
arr[0] = 1;
return arr;
}
}'Problem Solving > LeetCode' 카테고리의 다른 글
| [LeetCode] 69. Sqrt(x) - Java (0) | 2026.05.22 |
|---|---|
| [LeetCode] 67. Add Binary - Java (0) | 2026.05.21 |
| [LeetCode] 58. Length of Last Word - Java (0) | 2026.05.19 |
| [LeetCode] 35. Search Insert Position - Java (0) | 2026.05.18 |
| [LeetCode] 24. Swap Nodes in Pairs - Java (0) | 2026.05.17 |
댓글