leetcode 60-80 easy
66、Plus One
Given a non-empty array of digits representing a non-negative integer, plus one to the integer.
The digits are stored such that the most significant digit is at the head of the list, and each element in the array contain a single digit.
You may assume the integer does not contain any leading zero, except the number 0 itself.
Example 1:
- Input: [1,2,3]
- Output: [1,2,4]
- Explanation: The array represents the integer 123.
Example 2:
- Input: [4,3,2,1]
- Output: [4,3,2,2]
- Explanation: The array represents the integer 4321.
C++
- class Solution {
- public:
- vector<int> plusOne(vector<int> &digits) {
- bool carry = true;
- for(int i=digits.size()-; i >= && carry; i--) {
- carry = (++digits[i]%=) == ;
- }
- if(carry) {
- digits.insert(digits.begin(), );
- }
- return digits;
- }
- };
67. Add Binary
Given two binary strings, return their sum (also a binary string).
The input strings are both non-empty and contains only characters
1
or0
.Example 1:
- Input: a = "11", b = "1"
- Output: "100"
Example 2:
- Input: a = "1010", b = "1011"
- Output: "10101"
C++
- class Solution {
- public:
- string addBinary(string a, string b) {
- string s = "";
- int c = , i = a.size() - , j = b.size() - ;
- while(i >= || j >= || c == )
- {
- c += i >= ? a[i --] - '' : ;
- c += j >= ? b[j --] - '' : ;
- s = char(c % + '') + s;
- c /= ;
- }
- return s;
- }
- };
leetcode 60-80 easy的更多相关文章
- LeetCode:60. Permutation Sequence,n全排列的第k个子列
LeetCode:60. Permutation Sequence,n全排列的第k个子列 : 题目: LeetCode:60. Permutation Sequence 描述: The set [1, ...
- 【一天一道LeetCode】#80. Remove Duplicates from Sorted Array II
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Follow ...
- leetcode 26 80 删除已排序数组中重复的数据
80. Remove Duplicates from Sorted Array II Follow up for "Remove Duplicates":What if dupli ...
- LeetCode OJ 80. Remove Duplicates from Sorted Array II
题目 Follow up for "Remove Duplicates": What if duplicates are allowed at most twice? For ex ...
- LeetCode: 60. Permutation Sequence(Medium)
1. 原题链接 https://leetcode.com/problems/permutation-sequence/description/ 2. 题目要求 给出整数 n和 k ,k代表从1到n的整 ...
- 【Leetcode】【Easy】String to Integer (atoi)
Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. ...
- [LeetCode] 60. Permutation Sequence 序列排序
The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- leetcode第一题(easy)
第一题:题目内容 Given an array of integers, return indices of the two numbers such that they add up to a sp ...
- Java实现 LeetCode 60 第k个排列
60. 第k个排列 给出集合 [1,2,3,-,n],其所有元素共有 n! 种排列. 按大小顺序列出所有排列情况,并一一标记,当 n = 3 时, 所有排列如下: "123" &q ...
- 【LeetCode】80. 删除有序数组中的重复项 II
80. 删除有序数组中的重复项 II 知识点:数组:排序:双指针: 题目描述 给你一个有序数组 nums ,请你 原地 删除重复出现的元素,使每个元素 最多出现两次 ,返回删除后数组的新长度. 不要使 ...
随机推荐
- <随便写>创建文件批处理文件
创建一个text文档 写入想写的程序 将后缀改为bat 例如创建一个文件夹: 双击运行bat文件就可以创建文件夹 运行结果: 需要批量处理,就用for循环生成代码,粘贴上去就行了
- sqlserver2005分页存储过程
Create proc [dbo].[sp_AbiTableLoad] ---------------------------------------------- -- 单表多表分页存储过程 -- ...
- Java 多线程同步和异步详解
java线程 同步与异步 线程池 1)多线程并发时,多个线程同时请求同一个资源,必然导致此资源的数据不安全,A线程修改了B线 程的处理的数据,而B线程又修改了A线程处理的数理.显然这是由于全局资源造成 ...
- ERP或PLM系统-物料编码管理的技术实现
1 企业现状 企业日常经营过程中会产生大量的文档,如设计图纸.变更单.计算书.设计方案等,如果是制造企业还会产生大量的产品.组成产品的零部件等物料,这些数据在进入信息系统前都需要有一个唯一的标识,也就 ...
- P1080(python 高精度)
https://www.luogu.org/problem/P1080 n=int(input()) s=input().split() S=int(s[0]) T=int(s[1]) a=[] fo ...
- 在Spring框架中获取连接池的四种方式
1:DBCP数据源 DBCP类包位于 <SPRING_HOME>/lib/jakarta-commons/commons-dbcp.jar,DBCP是一个依赖Jakarta commons ...
- [转]Sql Server Alter语句
原文链接:http://www.cnblogs.com/yoolonet/archive/2010/12/10/1884782.html 在修改Sql Server表结构时,常用到Alter语句,把一 ...
- 矩阵快速幂3 k*n铺方格
#include <iostream> #include <cstdlib> #include <cstring> #include <queue> # ...
- VS中添加配置X86平台
最近IIS发布程序时,总是容易碰到下面的错误.这个错误网上绝大部分都是提出在VS把解决方案设置为在X86平台生成,然后再发布.但是查看应用程序后发现没有X86平台选项,下面是添加X86目标平台的方法.
- ArcMap应用——三维场景中井盖的属性配置
在精细三维场景中,有地面(包括道路面.马路牙子).有部件数据(包括井盖).我们会发现有马路牙子的地方比道路面要高出一部分,比如0.1米,但是雨水井盖却有些在路面上.有些在道路以外.就是说在道路面上的井 ...