题意让大数加1

我的做法是先让个位+1,再倒置digits,然后进位,最后倒置digits,得到答案。

 class Solution {
public:
vector<int> plusOne(vector<int> &digits) {
digits[digits.size() -]++; //个位+1
reverse(digits.begin(),digits.end());//倒置digits
for(vector<int>::size_type i = ; i < digits.size() - ; ++i){//除了最高位,进位
if(digits[i] >= ){
digits[i] -= ;
digits[i+] ++;
}
}
if(digits[digits.size() - ] >= ){//最高位进位
digits[digits.size() - ] -= ;
digits.push_back();
}
reverse(digits.begin(),digits.end());//倒置digits
return digits;
}
};

Leetcode 66 Plus One STL的更多相关文章

  1. 前端与算法 leetcode 66. 加一

    目录 # 前端与算法 leetcode 66. 加一 题目描述 概要 提示 解析 解法一 解法二 算法 # 前端与算法 leetcode 66. 加一 题目描述 给定一个由整数组成的非空数组所表示的非 ...

  2. LeetCode—66、88、118、119、121 Array(Easy)

    66. Plus One Given a non-negative integer represented as a non-empty array of digits, plus one to th ...

  3. 2017-3-7 leetcode 66 119 121

    今天纠结了一整天============================================================== leetcode66 https://leetcode.c ...

  4. Leetcode 290 Word Pattern STL

    Leetcode 205 Isomorphic Strings的进阶版 这次是词组字符串和匹配字符串相比较是否一致 请使用map来完成模式统计 class Solution { public: boo ...

  5. leetcode 66

    66. Plus One Given a non-negative number represented as an array of digits, plus one to the number. ...

  6. LeetCode 66. Plus One(加1)

    Given a non-negative integer represented as a non-empty array of digits, plus one to the integer. Yo ...

  7. LeetCode(66)题解: Plus One

    https://leetcode.com/problems/plus-one/ 题目: Given a non-negative number represented as an array of d ...

  8. [LeetCode] 66. Plus One 加一

    Given a non-empty array of digits representing a non-negative integer, plus one to the integer. The ...

  9. Java实现 LeetCode 66 加一

    66. 加一 给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一. 最高位数字存放在数组的首位, 数组中每个元素只存储单个数字. 你可以假设除了整数 0 之外,这个整数不会以零开头. 示 ...

随机推荐

  1. javascript 的 clientX用法

    <!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8&qu ...

  2. snmp switch traffic交换机带宽

    上代码 <?php function getstr1($strall,$str1,$str2,$html_charset='utf-8'){ $i1=mb_strpos($strall,$str ...

  3. SQL Server 查看物理页存储

    创建测试表 Use Test create table dbo.employee( emp_lname varchar(12) not null, emp_fname varchar(12)not n ...

  4. eclipse里面设置JVM参数的问题

    在run----run configuration---Agruments里面设置JVM的参数:  -Xms256m   -Xmx1024m 肯定还有别的方式设置,今天就先写这一种方法.待续...

  5. Wall--POJ1113(极角排序+求凸包)

    http://poj.org/problem?id=1113 题目大意:现在要给n个点,让你修一个围墙把这些点围起来,距离最小是l 分析  :现在就是求凸包的周长然后再加上一个圆的周长 #includ ...

  6. 无向图最小生成树(prim算法)

    普里姆算法(Prim算法),图论中的一种算法,可在加权连通图里搜索最小生成树.意即由此算法搜索到的边子集所构成的树中,不但包括了连通图里的所有顶点,且其所有边的权值之和亦为最小.该算法于1930年由捷 ...

  7. MyBatis源码分析(1)-MapConfig文件的解析

    1.简述 MyBatis是一个优秀的轻ORM框架,由最初的iBatis演化而来,可以方便的完成sql语句的输入输出到java对象之间的相互映射,典型的MyBatis使用的方式如下: String re ...

  8. oracle dblink调用函数

    select  用户名.函数名@DBLINK名称(参数) from dual; e.g. select newbosid@TEST('1234ECMA') from dual; -- 成功执行 sel ...

  9. 从一个Fragment跳转到另一个Fragment

    我们知道Activity之间的跳转可以使用 startActivity(intent).但Fragment之间的跳转却不能使用该方法,那该怎么办呢? 直接上代码: 核心代码 @Override//核心 ...

  10. day5----正则

    %a    本地(locale)简化星期名称     %A    本地完整星期名称     %b    本地简化月份名称     %B    本地完整月份名称     %c    本地相应的日期和时间 ...