66. Plus One
2016-03-10 21:23
253 查看
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.
题意:一个非负的数,各位存数组里,然后对这个数加1。
思路:加1,满10则进1.
The digits are stored such that the most significant digit is at the head of the list.
题意:一个非负的数,各位存数组里,然后对这个数加1。
思路:加1,满10则进1.
class Solution { public: vector<int> plusOne(vector<int>& digits) { int i = digits.size() - 1; while (i >= 0){ digits[i] += 1; if (digits[i] == 10){ digits[i] = 0; i--; } else{ break; } } if (i == -1){ digits.insert(digits.begin(), 1); } return digits; } };
相关文章推荐
- iOS项目实践之时光电影(二)
- string分割
- C语言中内存分配
- 一致性hash
- Problem B: 使用指针访问数组元素--程序填空
- python的入门教程 资源
- 【bzoj2300】[HAOI2011]防线修建 凸包+set
- 【D3D11系列教程】 第一讲 初始化Direct3D
- leetcode:Remove Nth Node From End of List 【Java】
- Hive命令行界面
- Test之guava
- 各层参数介绍,尤其数据层
- 御膳房数据开发平台学习
- ECshop Strict Standards: Only variables should be passed by reference in
- hihocoder 1260 String Problem I (Trie树 好题)
- 基因数据处理2之ftp数据快速查找
- jquery的end(),addBack()方法example
- Android基础——WebView使用(一)
- iOS_SN_地图的使用(2)
- Linux内核分析(三)