day64(1.23)——leetcode面试经典150

66. 加一

66. 加一

题目:

题解:

java 复制代码
class Solution {
    public int[] plusOne(int[] digits) {
        int n = digits.length - 1;
        for(int i=n;i>=0;i--) {
            if(digits[i]<9) {
                digits[i]++;
                return digits;
            }
            digits[i]=0;
        }
        //全是9,需要扩容
        int[] digit = new int[n+2];
        digit[0]=1;
        return digit;
    }
}
相关推荐
skywalker_116 小时前
力扣hot100-7(接雨水),8(无重复字符的最长子串)
算法·leetcode·职场和发展
田梓燊8 小时前
leetcode 160
算法·leetcode·职场和发展
Moment8 小时前
AI 全栈指南:NestJs 中的 Service Provider 和 Module
前端·后端·面试
Moment8 小时前
AI全栈入门指南:NestJs 中的 DTO 和数据校验
前端·后端·面试
Moment9 小时前
当前端开始做 Agent 后,我才知道 LangGraph 有多重要❗❗❗
前端·后端·面试
Ruihong10 小时前
你的 Vue 3 reactive(),VuReact 会编译成什么样的 React?
vue.js·面试
Ruihong10 小时前
你的 Vue 3 ref(),VuReact 会编译成什么样的 React?
vue.js·面试
yuki_uix11 小时前
跨域与安全:CORS、HTTPS 与浏览器安全机制
前端·面试
_深海凉_11 小时前
LeetCode热题100-找到字符串中所有字母异位词
算法·leetcode·职场和发展