LeetCode 第 66 題 (Plus One)
LeetCode 第 66 題 (Plus One)
Given a non-negative number represented as an array of digits, plus one to the number.
The digits are stored such that the most significant digit is at the head of the list.
這道題屬於比較簡單的那種。只要模擬手算加法的過程就行了。下面是程式碼。
vector<int> plusOne(vector<int>& digits)
{
int carry = 1;
for(int i = digits.size() - 1; i > -1 ; i--)
{
int val = carry + digits[i];
carry = (val) / 10;
digits[i] = (val) % 10;
}
if(carry)
{
digits.insert (digits.begin(), carry);
}
return digits;
}
相關文章
- LeetCode - Easy - 66. Plus OneLeetCode
- Leetcode: Plus OneLeetCode
- Leetcode Plus OneLeetCode
- [leetcode]plus-oneLeetCode
- Leetcode-Plus OneLeetCode
- Plus One leetcode javaLeetCodeJava
- 《HelloGitHub》第 66 期Github
- [LeetCode] 66. 加一LeetCode
- Leetcode第1~10題LeetCode
- LeetCode題解第122題LeetCode
- LeetCode刷題之第701題LeetCode
- LeetCode 第 69 題 (Sqrt(x))LeetCode
- LeetCode 第 7 題(Reverse Integer)LeetCode
- LeetCode 第 342 題(Power of Four)LeetCode
- LeetCode 第 343 題 (Integer Break)LeetCode
- LeetCode 第 50 題 (Pow(x, n))LeetCode
- LeetCode 第 9 題(Palindrome Number)LeetCode
- LeetCode 第 190 題 (Reverse Bits)LeetCode
- LeetCode 第 37 題 (Sudoku Solver)LeetCode
- LeetCode 第 326 題 (Power of Three)LeetCode
- LeetCode 第 65 題(Valid Number)LeetCode
- [leetcode 第 400 場周賽]題解LeetCode
- KMP演算法(Leetcode第28題)KMP演算法LeetCode
- leetcode的第9題:迴文數LeetCode
- LeetCode 第 231 題 (Power of Two)LeetCode
- LeetCode 第 191 題 (Number of 1 Bits)LeetCode
- LeetCode 第 338 題 (Counting Bits)LeetCode
- LeetCode 第 14 題(Longest Common Prefix)LeetCode
- Leetcode-One Edit DistanceLeetCode
- LeetCode-Number of Digit OneLeetCodeGit
- LeetCode Patching Array All In OneLeetCode
- LeetCode All in One 題目講解彙總(持續更新中...)LeetCode
- Leetcode 第136場周賽解題報告LeetCode
- LeetCode 第 125 題 (Valid Palindrome)LeetCode
- LeetCode 第 21 題 (Merge Two Sorted Lists)LeetCode
- 吐血整理Redis面試題66道Redis面試題
- 牛客周賽 Round 66 題解
- LeetCode 第 86 號問題:分割連結串列LeetCode