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 ,请你 原地 删除重复出现的元素,使每个元素 最多出现两次 ,返回删除后数组的新长度. 不要使 ...
随机推荐
- CentOS6安装docker、docker-compose、docker-enter
一.安装docker 1.查看CentOS内核版本 uname -r 2.安装Fedora的EPEL源 yum install http://ftp.riken.jp/Linux/fedora/epe ...
- 16_k近邻算法总结
1.k近邻算法属于分类算法 2.你的“邻居”来推断出你的类别 3.标准定义:如果一个样本在特征空间中的k个最相似(即特征空间中最邻近)的样本中的大多数属于某一个类别,则该样本也属于这个类别. 4.计算 ...
- Frame用navigate导航到新页面后导航条隐藏的方法
设置Frame的NavigationUIVisibility="Hidden"
- vue 实现邮戳边缘
效果: vue: <template> <div class="couponItem"> <div class="itemLeft" ...
- python-web-selenium模拟控制浏览器
用 selenium 模块控制浏览器 启动 selenium 控制的浏览器 from selenium import webdriver brower = webdriver.Firefox() br ...
- storm一些可调节的参数
# Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreeme ...
- JZOJ5895【NOIP2018模拟10.5】旅游
题目 Description
- springcloud-sleuth实现日志的链路追踪
1.需要将spring-cloud-starter-sleuth的依赖加入即可(注意:最好使用maven或gradle工具) 代码参考:https://github.com/Pinshuducha/s ...
- vue-cli 手机上浏览自己的项目
首先我们需要更改config文件 拿我这个项目举例子,config文件下的index.js内的dev下的host需要更改为自己的电脑IP 其次,重点来了,我们需要更改路径,细节的为什么我还解释不来,简 ...
- 19-10-16-R
其实……这篇是真咕了. 反思: ××我$T1$两个小时构造$xiebi$了(虽然我觉得如果干仨小时可能行?) ……如果$T1$用时过长的话那考试多半不行…… 结果: 35 Miemeng 50 03: ...