leetcode 之Plus One(9)
这题需要注意的是最后的进位
vector<int> plusOne(vector<int>& nums,int num)
{
add(nums, num);
}
void add(vector<int> &nums, int num)
{
int c = num;
for (auto it = nums.rbegin(); it != nums.rend(); it++)
{
*it += c;
*it = *it / ;
c = *it % ;
}
if (c > )
nums.insert(nums.begin(), );
}
leetcode 之Plus One(9)的更多相关文章
- 我为什么要写LeetCode的博客?
# 增强学习成果 有一个研究成果,在学习中传授他人知识和讨论是最高效的做法,而看书则是最低效的做法(具体研究成果没找到地址).我写LeetCode博客主要目的是增强学习成果.当然,我也想出名,然而不知 ...
- LeetCode All in One 题目讲解汇总(持续更新中...)
终于将LeetCode的免费题刷完了,真是漫长的第一遍啊,估计很多题都忘的差不多了,这次开个题目汇总贴,并附上每道题目的解题连接,方便之后查阅吧~ 477 Total Hamming Distance ...
- [LeetCode] Longest Substring with At Least K Repeating Characters 至少有K个重复字符的最长子字符串
Find the length of the longest substring T of a given string (consists of lowercase letters only) su ...
- Leetcode 笔记 113 - Path Sum II
题目链接:Path Sum II | LeetCode OJ Given a binary tree and a sum, find all root-to-leaf paths where each ...
- Leetcode 笔记 112 - Path Sum
题目链接:Path Sum | LeetCode OJ Given a binary tree and a sum, determine if the tree has a root-to-leaf ...
- Leetcode 笔记 110 - Balanced Binary Tree
题目链接:Balanced Binary Tree | LeetCode OJ Given a binary tree, determine if it is height-balanced. For ...
- Leetcode 笔记 100 - Same Tree
题目链接:Same Tree | LeetCode OJ Given two binary trees, write a function to check if they are equal or ...
- Leetcode 笔记 99 - Recover Binary Search Tree
题目链接:Recover Binary Search Tree | LeetCode OJ Two elements of a binary search tree (BST) are swapped ...
- Leetcode 笔记 98 - Validate Binary Search Tree
题目链接:Validate Binary Search Tree | LeetCode OJ Given a binary tree, determine if it is a valid binar ...
- Leetcode 笔记 101 - Symmetric Tree
题目链接:Symmetric Tree | LeetCode OJ Given a binary tree, check whether it is a mirror of itself (ie, s ...
随机推荐
- 洛谷 P4592 [TJOI2018]异或 解题报告
P4592 [TJOI2018]异或 题目描述 现在有一颗以\(1\)为根节点的由\(n\)个节点组成的树,树上每个节点上都有一个权值\(v_i\).现在有\(Q\)次操作,操作如下: 1 x y:查 ...
- Visual Studio 2010如何利用宏
最近在做后台代码的拆分,由于机器升级,原来装的添加注释的插件不能用了. 看来只有自己想办法了,看了下利用宏添加注释与把项目展开.折叠的方式: 参考了以下几个内容: 1.Visual Studio 20 ...
- 算法复习——欧拉回路(uoj117)
题目: 题解: 欧拉回路相关定理(相关定义和证明请参见其他资料): 1.欧拉回路 (1)有向图:所有点的出度都等于入度为该图为欧拉图(存在欧拉回路)的充要条件. (2)无向图:所有点的度都为偶数为该图 ...
- Linux之异步通知20160702
异步通知,主要说的是使用信号的方式,同时使用信号也是实现进程之间通信的一种方式. 多的不说,我们直接看代码: 首先应用程序的: #include <sys/types.h> #includ ...
- HDU 5646
DZY Loves Partition Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Ot ...
- [mysql][【优化集合】mysql数据库优化集合
三个层面: 1.系统层面 2.mysql配置参数 3.sql语句优化 =========================================================== 一.系统层 ...
- bzoj 4695 最假女选手 吉利线段树
最假女选手 Time Limit: 50 Sec Memory Limit: 128 MBSubmit: 480 Solved: 118[Submit][Status][Discuss] Desc ...
- svn全备加强版
svn版本库备份 官方建议使用如下方法备份(全备) svnadmin hotcopy path/to/repository path/to/backup 链接:https://tortoisesvn. ...
- 解决方案:WindowsError: [Error 2]
使用Python的rename()函数重命名文件时出现问题,提示 WindowsError: [Error 2] 错误,最初代码如下: def renameFile(filename): filePr ...
- lua 闪电特效
闪电特效 根据不同的起点 终点 资源做倾斜 拉伸 ,主要是计算倾斜角度. function ZyLight:show(params) local params = params or {} local ...