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
1or0.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 ,请你 原地 删除重复出现的元素,使每个元素 最多出现两次 ,返回删除后数组的新长度. 不要使 ...
随机推荐
- C语言实现 计算个人所得税务2种方法
#include <stdio.h> #include <stdlib.h> /* 基于C语言的个人所得税计税系统 问题描述: 我国现行的个人所得税计算方法如下: 级数 全月应 ...
- eclipse memory analyzer对系统内存溢出堆文件解析(转)
本文转之:https://blog.csdn.net/rachel_luo/article/details/8992461 前言 性能分析工具之-- Eclipse Memory Analyzer t ...
- ES6之主要知识点(七)对象
1.属性的简洁表示法 ES6 允许直接写入变量和函数,作为对象的属性和方法.这样的书写更加简洁. function f(x, y) { return {x, y}; } // 等同于 function ...
- elasticsearch query 和 filter 的区别
Query查询器 与 Filter 过滤器 尽管我们之前已经涉及了查询DSL,然而实际上存在两种DSL:查询DSL(query DSL)和过滤DSL(filter DSL).过滤器(filter)通常 ...
- 简单的sequence unpacking
t = (1, 2, ‘hl’) x, y, z = t 上述方法可用于任何sequence
- linear-gradient
http://jsbin.com/mocojehosa/edit?html,css,output https://developer.mozilla.org/zh-CN/docs/Web/CSS/li ...
- iframe加载完成事件
var iframe = document.createElement("iframe"); iframe.src = "http://www.jb51.net" ...
- tinyproxy 反向代理无法上网原因
今天参照网上教程在服务器安装并配置了tinyproxy反向代理,此次安装反向代理的目的主要是通过内网连接上服务器,再使用服务器作为中转站进行上网.安装并启动的主要步骤如下 下载并安装tinypro ...
- 装配SpringBean(六)--配置文件加载方式
spring中的配置文件有两种: 以XML结尾的spring配置文件 以properties结尾的属性配置文件 在spring中有两种方式加载这两种文件: 通过注解+java配置的方式 通过XML的方 ...
- 微信小程序开发(一)
引自http://www.cnblogs.com/mdnx/p/6004653.html 第一步 (下载开发工具) https://mp.weixin.qq.com/debug/wxadoc/dev ...