http://oj.leetcode.com/problems/plus-one/

进位加法

#include <iostream>
#include <vector> using namespace std; class Solution {
public:
vector<int> plusOne(vector<int> &digits) {
// IMPORTANT: Please reset any member data you declared, as
// the same Solution instance will be reused for each test case.
vector<int> ansVector; if(digits.empty())
return digits;
vector<int>::iterator iter = digits.end()-; while(iter!=digits.begin())
{
if(*iter!=)
{
*iter = *iter +;
return digits;
}
*iter = ;
iter--;
}
if(digits[]!=)
{
digits[]+=;
return digits;
}
ansVector.push_back();
for(int i = ;i<digits.size();i++)
ansVector.push_back();
return ansVector;
}
}; int main()
{
Solution mySolution;
vector<int> input;
input.push_back();
input.push_back();
mySolution.plusOne(input);
return ;
}

LeetCode OJ——Plus One的更多相关文章

  1. LeetCode OJ 题解

    博客搬至blog.csgrandeur.com,cnblogs不再更新. 新的题解会更新在新博客:http://blog.csgrandeur.com/2014/01/15/LeetCode-OJ-S ...

  2. 【LeetCode OJ】Interleaving String

    Problem Link: http://oj.leetcode.com/problems/interleaving-string/ Given s1, s2, s3, find whether s3 ...

  3. 【LeetCode OJ】Reverse Words in a String

    Problem link: http://oj.leetcode.com/problems/reverse-words-in-a-string/ Given an input string, reve ...

  4. LeetCode OJ学习

    一直没有系统地学习过算法,不过算法确实是需要系统学习的.大二上学期,在导师的建议下开始学习数据结构,零零散散的一学期,有了链表.栈.队列.树.图等的概念.又看了下那几个经典的算法——贪心算法.分治算法 ...

  5. LeetCode OJ 297. Serialize and Deserialize Binary Tree

    Serialization is the process of converting a data structure or object into a sequence of bits so tha ...

  6. 备份LeetCode OJ自己编写的代码

    常泡LC的朋友知道LC是不提供代码打包下载的,不像一般的OJ,可是我不备份代码就感觉不舒服- 其实我想说的是- 我自己写了抓取个人提交代码的小工具,放在GitCafe上了- 不知道大家有没有兴趣 ht ...

  7. LeetCode OJ 之 Maximal Square (最大的正方形)

    题目: Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and ...

  8. LeetCode OJ:Integer to Roman(转换整数到罗马字符)

    Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 t ...

  9. LeetCode OJ:Serialize and Deserialize Binary Tree(对树序列化以及解序列化)

    Serialization is the process of converting a data structure or object into a sequence of bits so tha ...

  10. 【LeetCode OJ】Validate Binary Search Tree

    Problem Link: https://oj.leetcode.com/problems/validate-binary-search-tree/ We inorder-traverse the ...

随机推荐

  1. php通过geohash算法实现查找附近的商铺

    geohash有以下几个特点: 首先,geohash用一个字符串表示经度和纬度两个坐标.利用geohash,只需在一列上应用索引即可. 其次,geohash表示的并不是一个点,而是一个矩形区域.比如编 ...

  2. Django 惰性机制

    惰性机制:Publisher.objects.all()或者.filter()等都只是返回了一个QuerySet(查询结果集对象),它并不会马上执行sql,而是当调用QuerySet的时候才执行sql ...

  3. GoF23种设计模式之行为型模式之中介者模式

    一.概述 使用一个中介对象来封装一系列的对象交互.中介者让各个对象无需显式地相互引用,从而达到解耦的效果.并且可以独立地改变它们之间的交互.二.适用性1.当一组对象以定义良好但复杂通信的时候.产生的相 ...

  4. 命令行执行Qt程序

    原文网址 //helloworld.cpp #include <QApplication> #include <QPushButton> int main(int argc,c ...

  5. Mysql中的联合索引、前缀索引、覆盖索引

    索引 索引是一种特殊的文件,它们包含着对数据表里所有记录的引用指针.更通俗的说,数据库索引好比是一本书前面的目录,能加快数据库的查询速度. 联合索引 又名复合索引,由两个或多个列的索引.它规定了mys ...

  6. UIAutomator输入中文

    之前一直是英文的测试环境,包括手机也是英文的,app也是英文的,涉及不到中文输入法的东西.但现在在写中文的app,所以需要输入中文.看到网上的解决办法如下: 下载https://github.com/ ...

  7. springboot-vue-前后端数据交互

    前端项目: pom文件: <?xml version="1.0" encoding="UTF-8"?> <project xmlns=&quo ...

  8. loj2182 「SDOI2015」寻宝游戏

    参考这里 #include <iostream> #include <cstdio> #include <set> using namespace std; typ ...

  9. webdriver高级应用- 精确比较页面截图图片

    判断两张图是否完全一致,如果存在任何不一致,会认为图片不匹配,代码如下: #encoding=utf-8 from selenium import webdriver import unittest, ...

  10. install chrome on ubuntu14.04

    summary chrome broswer can't found in ubuntu14.04 default source list.To install chrome ,you must ad ...