LeedCode 之 Plus One
来源:互联网 发布:矩阵型组织结构 编辑:程序博客网 时间:2024/06/06 01:57
题目链接:Plus One
这道题属于简单,但是不知道是英语差还是怎么得,我没看懂题目,搜了下其他人对这个题目的理解,才发现原来如此,挺简单的~
题意:使用数组来记录一个整数,设置数组digits,如整数98,那么digits[0]=9,digits[1]=8;加1以后,依次进位,如果超过原数组的长度,那么就新建一个数组,将原数组复制到新数组,并设置最高位为1。
代码:
public class Solution { public int[] plusOne(int[] digits) { int len = digits.length; for(int i=len-1;i>-1;i--) { if(digits[i]<9) { digits[i]++; return digits; } else digits[i]=0; } if(digits[0]==0) { int[] newdigits =new int[len+1]; System.arraycopy(digits, 0, newdigits, 1, len); newdigits[0]=1; return newdigits; } return digits; }}
0 0
- LeedCode 之 Plus One
- leetcode之Plus One
- LeetCode 之 Plus One
- LeetCode之Plus One
- leetcode之Plus One
- LeetCode之Plus One
- leetcode之plus one
- leetcode之Plus One
- leetcode之plus One
- leetcode之Plus One
- 【Leetcode】之Plus One
- leetcode数组之Plus One
- Leetcode之Plus One 问题
- LeetCode算法题之Plus One
- LeetCode 之 Plus One — C 实现
- Plus One
- Plus One
- Plus One
- socket函数send和recv函数
- ffmpeg基础知识
- 用python-pulp解决线性规划问题
- web.xml配置,避免乱码
- 解决:Xvfb 缺少cyrillic 100dpi 75dpi 100dpi 75dpi
- LeedCode 之 Plus One
- PHPword 表格内换行处理
- STL:set详解
- Joint Face Detection and Alignment Using Multi-task Cascade Convolutional Networks笔记
- mybatis generator xml配置模板
- [Leetcode] #343 Integer Break (DP)
- RateLimit--使用guava来做接口限流
- 虚拟机装win7
- Utgard使用总结(OPC)