参考资料:左程云算法课

66. 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-right order. The large integer does not contain any leading 0's.Increment the large integer by one and return the resulting array of digits.Example 1:Input: digits = [1,2,3]
Output: [1,2,4]
Explanation: The array represents the integer 123.
Incrementing by one gives 123 + 1 = 124.
Thus, the result should be [1,2,4].

思路:
倒序遍历,遇到第一个不为9的位加一并结束返回数组,否则(也就是当前位是9)直接化为0.
如果遍历结束,还没有结束返回值,那么说明原数组中都是9,于是 创建新数组,手动加一。

 public static int[] plusOne(int[] digits){// 9,9,9int n = digits.length;// i=n-1 for(int i=n-1;i>=0;i++){if(digits[i]<9){digits[i]+=1;return digits;}digits[0]=0;}int[] ans = new int[n+1];ans[0]=1;return ans;}

LeetCode !! 69 plusOne相关推荐

  1. 【分治】LeetCode 69. Sqrt(x)

    LeetCode 69. Sqrt(x) 参考网址:http://www.cnblogs.com/grandyang/p/4346413.html Solution1: class Solution ...

  2. LeetCode #69 x的平方根 二分查找

    LeetCode #69 x的平方根 题目描述 实现 int sqrt(int x) 函数. 计算并返回 x 的平方根,其中 x 是非负整数. 由于返回类型是整数,结果只保留整数的部分,小数部分将被舍 ...

  3. LeetCode 69. x 的平方根:二分查找法实现自定义的函数:x 的平方根

    LeetCode 69. x 的平方根:二分查找法实现自定义的函数:x 的平方根 题目描述 实现 int sqrt(int x) 函数. 计算并返回 x 的平方根,其中 x 是非负整数. 由于返回类型 ...

  4. LeetCode - 69. x 的平方根

    69. x 的平方根 class Solution {private static final Integer MAX_POW = 46340;/*** 牛顿迭代* f(x) = x^2 - n* 切 ...

  5. LeetCode 69. x 的平方根(二分查找)

    文章目录 1. 题目 2.解题 2.1 二分查找 2.2 牛顿迭代 1. 题目 实现 int sqrt(int x) 函数. 计算并返回 x 的平方根,其中 x 是非负整数. 由于返回类型是整数,结果 ...

  6. 1.1.3 数组——x的平方(Leetcode 69)

    x的平方 1. 题目 2. 思路 3. 代码实现 4. 总结 1. 题目 leetcode链接 给你一个非负整数 x ,计算并返回 x 的 算术平方根 . 由于返回类型是整数,结果只保留 整数部分 , ...

  7. 【手绘漫画】图解LeetCode之x 的平方根(LeetCode 69题)

    文章目录 图解LeetCode刷题计划 1.写在前面 2.题目 3.正文 4.代码 图解LeetCode刷题计划 1.写在前面 手绘漫画系列正式上线!!!"图解LeetCode刷题计划&qu ...

  8. LeetCode——69 x的平方根

    问题描述: 实现 int sqrt(int x) 函数.计算并返回 x 的平方根,其中 x 是非负整数.由于返回类型是整数,结果只保留整数的部分,小数部分将被舍去. 示例 1: 输入: 4 输出: 2 ...

  9. LeetCode:69. Sqrt(x)

    题目链接: 69. Sqrt(x) 题目描述: Implement int sqrt(int x) Compute and return the square root of x. 题目解释: 提干非 ...

最新文章

  1. MySQL的常见存储引擎介绍与参数设置调优
  2. JavaScript学习笔记——BOM_window对象
  3. ODataModel.submitBatch by default Asynchronous
  4. Redis非阻塞I/O多路复用机制
  5. python 生成器_提高你的Python: 解释‘yield’和‘Generators(生成器)’
  6. 设置html按钮点击事件无效果,css怎么设置按钮不能点击?
  7. python开发蠕虫病毒_清除服务器蠕虫病毒
  8. git(5)---Git 与Repo 管理Android代码
  9. 【C++】C++中substr的用法
  10. 快递100 快递公司编码-标准国际
  11. Oracle 11g SQL基础入门系列培训-小布作品
  12. MATLAB 常用函数学习笔记
  13. 成功三大定律 重在厚积薄发!
  14. Unity实现自适应屏幕大小——九宫格
  15. 【一点唐城】15个未来高科技产品会让你无法想象、这些开脑洞的设计太牛了
  16. 数据结构C语言 胡学钢 PDF,数据结构(C语言版) 胡学钢.ppt
  17. ENSP 单臂路由的配置(带配置命令)
  18. 人工智能最受欢迎的10大TED演讲
  19. feasycom蓝牙对接Android,2.4G低功耗蓝牙解决方案
  20. 菜鸟级MVC登录注册实现

热门文章

  1. 以同样的姿势在同样的地方拍照(深深的感动)
  2. 全球及中国智能建筑行业十四五规模预测与发展格局分析报告2021版
  3. wltc循环多少公里_究竟是不是大忽悠?聊聊官方续航里程的含金量!
  4. R-GUI:图形界面介绍
  5. 多线程计算数据,然后合并数据
  6. 2020省赛 填空 蛇形填数 java
  7. 平方矩阵(回字形矩阵)
  8. Java jar包解压
  9. 算法图解---狄杰斯特拉算法(原理+代码)
  10. 街霸真人版 Sagat vs 豪鬼 瞬狱杀的真实面目