美文网首页
LeetCode-加一

LeetCode-加一

作者: 沙漠小舟 | 来源:发表于2020-03-30 22:03 被阅读0次

题目链接 => 戳这里

题目截图

解法:这道题其实有点像两数相加那道题

class Solution {
    public int[] plusOne(int[] digits) {
        for (int i = digits.length - 1; i >= 0; i--) {
            digits[i]++;
            digits[i] = digits[i] % 10;
            if (digits[i] != 0) {
                return digits;
            }
        }
        digits = new int[digits.length + 1];
        digits[0] = 1;
        return digits;
    }
}

相关文章

  • LeetCode-加一

    给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一。最高位数字存放在数组的首位, 数组中每个元素只存...

  • leetcode-加一

    加一给定一个非负整数组成的非空数组,在该数的基础上加一,返回一个新的数组。最高位数字存放在数组的首位, 数组中每个...

  • leetcode- 加一

    给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一。 最高位数字存放在数组的首位, 数组中每个元素只...

  • LeetCode-加一

    题目链接 => 戳这里 解法:这道题其实有点像两数相加那道题

  • 【leetcode-动态规划】Longest Increasin

    【leetcode-动态规划】Longest Increasing Subsequence 给定一个无序的整数数组...

  • leetcode-数组-加一|Plus One(Python3)

    给定一个非负整数组成的非空数组,在该数的基础上加一,返回一个新的数组。 最高位数字存放在数组的首位, 数组中每个元...

  • 一起学算法-69. x 的平方根

    一、题目 LeetCode-算法入门-69. x 的平方根地址:https://leetcode-cn.com/p...

  • LeetCode-股票问题

    LeetCode-股票问题 121. 买卖股票的最佳时机[https://leetcode-cn.com/prob...

  • 算法—字符串编码

    题目: 字符串编码(LeetCode-中等) 编码规则为: k[encoded_string],表示其中方括号内部...

  • 【leetcode-动态规划】零钱兑换

    【leetcode-动态规划】零钱兑换 给定不同面额的硬币 coins 和一个总金额 amount。编写一个函数来...

网友评论

      本文标题:LeetCode-加一

      本文链接:https://www.haomeiwen.com/subject/pobbuhtx.html