题目:对一个用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. 【J2SE】java实现简单照片查看器

    程序执行结果: project结构图: 程序代码: import java.awt.BorderLayout; import java.awt.FileDialog; import java.awt. ...

  2. Team Foundation Server 2015使用教程--团队项目创建

  3. wamp You don't have permission to access / on this server等问题的解决.

    原文:wamp You don't have permission to access / on this server等问题的解决. 安装完wamp之后,安装网上的教程设置虚拟路径,出现了问题,同样 ...

  4. 常见的FPGA内串行数据采样的方式

    总结下常见的对串行数据采样的三种方式: 1. 全采样存储方式: 采用过采样,用过采样时钟,用移位寄存器移位,把每次采样值都存起来.采用高速的过采样时钟运行. 然后等待触发条件,(就是找到数据的起始点条 ...

  5. Installing IIS 8.5 on Windows Server 2012 R2

    原文 Installing IIS 8.5 on Windows Server 2012 R2 Introduction This document describes how to install ...

  6. (大数据工程师学习路径)第四步 SQL基础课程----创建数据库并插入数据

    一.练习内容 1.新建数据库 首先,我们创建一个数据库,给它一个名字,比如“mysql_shiyan”,以后的几次实验也是对mysql_shiyan这个数据库进行操作. 语句格式为“CREATE DA ...

  7. 微软可疑更新DhMachineSvc.exe

    微软最近推出了大规模的更新仅针对中国.它包括DhMachineSvc.exe.所谓'微软设备健康助手服务'. 此更新是惊人的,首先,此更新只针对中国地区,其次,此更新支持WinXP,第三次更新一定的强 ...

  8. dotNET跨平台相关文档

    dotNET跨平台相关文档整理 一直在从事C#开发的相关技术工作,从C# 1.0一路用到现在的C# 6.0, 通常情况下被局限于Windows平台,Mono项目把我们C#程序带到了Windows之外的 ...

  9. android layout物业介绍

    android:id 为控件指定对应的ID android:text 指定控件其中显示的文字,须要注意的是,这里尽量使用strings.xml文件其中的字符串 android:gravity 指定Vi ...

  10. 最少换乘(Dijkstra)

    Description 欧洲某城是一个著名的旅游胜地,每年都有成千上万的人前来观光旅行.Dr. Kong决定利用暑假好好游览一番.. 年轻人旅游不怕辛苦,不怕劳累,只要费用低就行.但Dr. Kong年 ...