LeetCode66. Plus One
来源:互联网 发布:亚麻籽粉 知乎 编辑:程序博客网 时间:2024/06/03 21:41
Given a non-negative integer represented as a non-empty array of digits, plus one to the integer.
You may assume the integer do not contain any leading zero, except the number 0 itself.
The digits are stored such that the most significant digit is at the head of the list.
#include<vector>#include<iostream>using namespace std;class Solution {public: vector<int> plusOne(vector<int>& digits) { int n=digits.size(); if(n==0){ digits.push_back(1); return digits; } else{ for(int i=n-1;i>-1;--i){ if(digits[i]<9){ digits[i]=digits[i]+1; return digits; } else{ digits[i]=0; if(i==0){ digits.insert(digits.begin(),1); } } } return digits; } }};void main(){ vector<int> v; v.push_back(2); v.push_back(4); v.push_back(9); v.push_back(3); v.push_back(9); Solution So; vector<int> res=So.plusOne(v); int n=res.size(); for(int i=0;i<n;++i){ cout<<res[i]<<" "; }}
0 0
- LeetCode66: Plus One
- leetcode66.[Array] Plus One
- leetcode66: Plus One
- leetcode66~Plus One
- LeetCode66. Plus One
- LeetCode66. Plus One
- LeetCode66 Plus One
- leetcode66-Plus One
- LeetCode66——Plus One
- LeetCode66——Plus One
- leetcode66-Plus One(加1问题)
- LeetCode66/169/79 Plus One/Majority Element /Word Search
- LeetCode66——Plus One(一个整数用数组存储,然后在末尾加1)
- 字符串可以按位获得和列表生成式-【leetcode66-plus one】
- Plus One
- Plus One
- Plus One
- Plus One
- Android通过ContentProvider获取通话记录
- MFC基础知识
- Lintcode 搜索区间
- HTML编程快速入门教程
- Unity3D学习——井字棋游戏
- LeetCode66. Plus One
- linux运维-系统服务的控制
- 家装类网站建设如何定位和优化运营
- 练习
- 基于node.js的简单本地服务器搭建
- 剑指offer:二叉搜索树与双向链表
- npm 安装 bin/npm: line 1: ../lib/node_modules/npm/bin/npm-cli.js: No such file or directory
- 陷阱还是馅饼!聊聊企业模板建站的那些事
- 带分数