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. java中的final关键字(2013-10-11-163 写的日志迁移

     final关键字:修饰符,表示最后的.最终的    修饰类: 表示该类不能派生子类(不能被继承)   1.当不希望父类的的某个方法被子类覆盖(override)时,可以用final关键字来修饰.   ...

  2. 《linux设备驱动开发详解》笔记——14 linux网络设备驱动

    14.1 网络设备驱动结构 网络协议接口层:硬件无关,标准收发函数dev_queue_xmit()和netif_rx();  注意,netif_rx是将接收到的数据给上层,有时也在驱动收到数据以后调用 ...

  3. 水题:51Nod1432-独木舟

    1432 独木舟 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题 Problem Description n个人,已知每个人体重.独木舟承重固定,每只独木舟最多坐两 ...

  4. MIP启发式算法:遗传算法 (Genetic algorithm)

    *本文主要记录和分享学习到的知识,算不上原创 *参考文献见链接 本文主要讲述启发式算法中的遗传算法.遗传算法也是以local search为核心框架,但在表现形式上和hill climbing, ta ...

  5. chrome无界面模式headless配置

    引入Options: 配置浏览器: 配置浏览器options,然后传入webdriver.Chrome()就可以成功使用了.

  6. python中子进程不支持input()函数输入

    错误的源代码: import socketimport threadingimport multiprocessing# 创建socketserve_socket = socket.socket(so ...

  7. python基础学习笔记——单继承

    1.为什么要有类的继承性?(继承性的好处)继承性的好处:①减少了代码的冗余,提供了代码的复用性②提高了程序的扩展性 ③(类与类之间产生了联系)为多态的使用提供了前提2.类继承性的格式:单继承和多继承# ...

  8. static_cast 、const_cast、dynamic_cast、reinterpret_cast 关键字简单解释

    static_cast .const_cast.dynamic_cast.reinterpret_cast 关键字简单解释: Static_cast 静态类型转换 ①用于类层次结构中基类(父类)和派生 ...

  9. 深入浅出理解Javascript原型概念以及继承机制(转)

    在Javascript语言中,原型是一个经常被讨论到但是有非常让初学者不解的概念.那么,到底该怎么去给原型定义呢?不急,在了解是什么之前,我们不妨先来看下为什么. Javascript最开始是网景公司 ...

  10. Python socket粘包问题(最终解决办法)

    套接字: 就是将传输层以下的协议封装成子接口 对于应用程序来说只需调用套接字的接口,写出的程序自然是遵循tcp或udp协议的 实现第一个功能个:实现:通过客户端向服务端发送命令,调取windows下面 ...