https://leetcode.com/problems/plus-one/
题目:
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位,逢9进1。注意999这种情况要首位insert1。
1 class Solution { 2 public: 3 vector<int> plusOne(vector<int>& digits) { 4 int n=digits.size(); 5 bool jinyi=false; 6 for(int i=n-1;i>=0;i--){ 7 if(digits[i]==9){ 8 digits[i]=0; 9 jinyi=true; 10 } 11 else{ 12 digits[i]++; 13 jinyi=false; 14 break; 15 } 16 } 17 if(jinyi==true){ 18 vector <int>::iterator theIterator = digits.begin(); 19 digits.insert(theIterator,1,1); 20 } 21 return digits; 22 } 23 };
· 记一次 .NET某固高运动卡测试 卡慢分析
· 微服务架构学习与思考:微服务拆分的原则
· 记一次 .NET某云HIS系统 CPU爆高分析
· 如果单表数据量大,只能考虑分库分表吗?
· 一文彻底搞懂 MCP:AI 大模型的标准化工具箱
· 博客园2025新款「AI繁忙」系列T恤上架
· Avalonia跨平台实战(二),Avalonia相比WPF的便利合集(一)
· C# LINQ 快速入门实战指南,建议收藏学习!
· 记一次 .NET某固高运动卡测试 卡慢分析
· 上周热点回顾(4.7-4.13)