题目:对一个用vector存的数字进行加1,然后返回加1后的值。

一次就在oj上通过了。

就是进位加上当前位如果大于9,那就当前位等于0;

随后进位还为1的话就是在数组前面插入一个1;

class Solution {
public:
vector<int> plusOne(vector<int> &digits)
{
int up = ;
int len = digits.size() - ;
while(len >= )
{
if (digits[len] + up > )
{
digits[len] = ;
}
else
{
digits[len] += up;
return digits;
}
len--;
}
digits.insert(digits.begin(), );
return digits;
}
};

2015/03/29:

python:

class Solution:
# @param digits, a list of integer digits
# @return a list of integer digits
def plusOne(self, digits):
up = 1
length = len(digits) - 1
for i in range(len(digits)):
digits[length-i] += up
up = digits[length-i]/10
digits[length-i] %= 10
if up == 1:
digits.insert(0, 1)
return digits

leetcode[67] Plus One的更多相关文章

  1. # Leetcode 67:Add Binary(二进制求和)

    Leetcode 67:Add Binary(二进制求和) (python.java) Given two binary strings, return their sum (also a binar ...

  2. leetcode 67

    67. Add Binary Given two binary strings, return their sum (also a binary string). For example,a = &q ...

  3. LeetCode(67)题解: Add Binary

    https://leetcode.com/problems/add-binary/ 题目: Given two binary strings, return their sum (also a bin ...

  4. LeetCode 67. Add Binary (二进制相加)

    Given two binary strings, return their sum (also a binary string). For example,a = "11"b = ...

  5. [LeetCode] 67. Add Binary 二进制数相加

    Given two binary strings, return their sum (also a binary string). The input strings are both non-em ...

  6. Java实现 LeetCode 67 二进制求和

    67. 二进制求和 给定两个二进制字符串,返回他们的和(用二进制表示). 输入为非空字符串且只包含数字 1 和 0. 示例 1: 输入: a = "11", b = "1 ...

  7. Leetcode 67 Add Binary 大数加法+字符串处理

    题意:两个二进制数相加,大数加法的变形 大数加法流程: 1.倒置两个大数,这一步能使所有大数对齐 2.逐位相加,同时进位 3.倒置两个大数的和作为输出 class Solution { public: ...

  8. LeetCode 67. Add Binary

    Given two binary strings, return their sum (also a binary string). For example,a = "11"b = ...

  9. Java [Leetcode 67]Add Binary

    题目描述: Given two binary strings, return their sum (also a binary string). For example,a = "11&qu ...

随机推荐

  1. zoj-3795-Grouping-tarjan确定最长的公路收缩

    使用tarjan缩合点. 然后,dfs寻找最长的公路. 水体. . . #include<stdio.h> #include<string.h> #include<alg ...

  2. T-SQL性能调整——信息收集

    原文:T-SQL性能调整--信息收集 IO信息(自服务器启动开始) --Database IO analysis WITH IOFORDATABASE AS ( SELECT DB_NAME(VFS. ...

  3. oracle connect by 说明

    Oracle能够通过START WITH . . . CONNECT BY . . .子句来实现SQL分层查询,这递归查询 例如: select level||'月' 月份 from dual con ...

  4. hdu2571命

    称号: Problem Description 穿过幽谷意味着离大魔王lemon已经无限接近了! 可谁能想到,yifenfei在斩杀了一些虾兵蟹将后.却再次面临命运大迷宫的考验.这是魔王lemon设下 ...

  5. 采用Visual Stuidio 2010 创建网站栏

    采用Visual Stuidio 2010 创建网站栏 Visual Stuidio 2010 该项目模板使创建网站栏/内容类型和列表变得非常方便. 1. 管理员身份打开Visual Stuidio ...

  6. (大数据工程师学习路径)第二步 Vim编辑器----高级功能入门

    一.多文件编辑 1.使用vim编辑多个文件 编辑多个文件有两种形式,一种是在进入vim前使用的参数就是多个文件.另一种就是进入vim后再编辑其他的文件. 同时创建两个新文件并编辑 $ vim 1.tx ...

  7. [DB][mybatis]MyBatis mapper文件引用变量#{}与${}差异

    MyBatis mapper文件引用变量#{}与${}差异 默认,使用#{}语法,MyBatis会产生PreparedStatement中.而且安全的设置PreparedStatement參数,这个过 ...

  8. 我的MYSQL学习心得(三)

    原文:我的MYSQL学习心得(三) 我的MYSQL学习心得(三) 我的MYSQL学习心得(一) 我的MYSQL学习心得(二) 我的MYSQL学习心得(四) 我的MYSQL学习心得(五) 我的MYSQL ...

  9. windows下系统移植到linux下出现的问题

    今天遇到了一个之前没有遇到的问题,记录一下. 我们是在windows下进行开发的,最终系统是部署在linux服务器上. 在windows一切正常,但是部署到linux下时,有些功能不能用了.通过log ...

  10. Codeforces Round #248 (Div. 2) (ABCD解决问题的方法)

    比赛链接:http://codeforces.com/contest/433 A. Kitahara Haruki's Gift time limit per test:1 second memory ...