leetcode66
public class Solution {
public int[] PlusOne(int[] digits) {
var last = digits[digits.Length - ];
if (last + < )
{
digits[digits.Length - ]++;
return digits;
}
else
{
var list = new List<int>();
int step = ;
for (int i = digits.Length - ; i >= ; i--)
{
var cur = digits[i];
cur = cur + step;
if (cur >= )
{
step = ;
}
else
{
step = ;
}
list.Add(cur % );//原来肯定是9,9+1变为10
}
if (step == )
{
list.Add();
}
list.Reverse();
return list.ToArray();
}
}
}
https://leetcode.com/problems/plus-one/#/description
补充一个python的实现:
class Solution:
def plusOne(self, digits: List[int]) -> List[int]:
n = len(digits)
temp = [] * n
up =
last = digits[-]
last +=
if last == :
temp[-] =
up =
else:
temp[-] = last for i in range(n-,-,-):
cur = digits[i]
cur += up
if cur == :
temp[i] =
up =
else:
temp[i] = cur
up =
if up == :
temp.insert(,)
return temp
leetcode66的更多相关文章
- leetcode-66.加一
leetcode-66.加一 题意 给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一. 最高位数字存放在数组的首位, 数组中每个元素只存储一个数字. 你可以假设除了整数 0 之外,这个 ...
- LeetCode----66. Plus One(Java)
package plusOne66; /* Given a non-negative number represented as an array of digits, plus one to the ...
- [LeetCode66]Plus One
题目: Given a non-negative number represented as an array of digits, plus one to the number. The digit ...
- [Swift]LeetCode66. 加一 | Plus One
Given a non-empty array of digits representing a non-negative integer, plus one to the integer. The ...
- leetCode66:加一
/** * @param {number[]} digits * @return {number[]} */ var plusOne = function(digits) { if(digits[di ...
- 【leetcode-66】 加一
给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一. 最高位数字存放在数组的首位, 数组中每个元素只存储一个数字. 你可以假设除了整数 0 之外,这个整数不会以零开头. 示例 1: 输入 ...
- 2017-3-7 leetcode 66 119 121
今天纠结了一整天============================================================== leetcode66 https://leetcode.c ...
随机推荐
- java8 array、list操作 汇【4】)- Java8 Lambda表达式 函数式编程
int tmp1 = 1; //包围类的成员变量 static int tmp2 = 2; //包围类的静态成员变量 //https://blog.csdn.net/chengwangbaiko/ar ...
- org.apache.commons.lang3.Validate
Validates.notBlank(user.getName(), "必须提供name");
- UVA11525 【Permutation】
分析 简述"康托展开" 康托展开是一个全排列到一个自然数的双射,常用于构建hash表时的空间压缩.设有\(n\)个数\((1,2,3,4,-,n)\),可以有组成不同(\(n!\) ...
- MFC 对话框Picture Control(图片控件)中静态和动态显示Bmp图片
版权声明:本文为博主原创文章,转载请注明CSDN博客源地址! 共同学习,一起进步~ https://blog.csdn.net/Eastmount/article/details/26404733 ...
- log4net保存到数据库系列二:独立配置文件中配置log4net
园子里面有很多关于log4net保存到数据库的帖子,但是要动手操作还是比较不易,从头开始学习log4net数据库日志一.WebConfig中配置log4net 一.WebConfig中配置log4ne ...
- Linux 安装Jdk、mysql、apache、php、tomcat、nginx
Jdk 安装分三步:第一步,上传跟 linux 位数相同的 jdk tar 包,解压:第二步:解压 tar 包,配置环境变量,且 source 一下 /etc/profile:第三步:检查版本 第一步 ...
- 【转】每天一个linux命令(54):ping命令
原文网址:http://www.cnblogs.com/peida/archive/2013/03/06/2945407.html Linux系统的ping命令是常用的网络命令,它通常用来测试与目标主 ...
- 【转】每天一个linux命令(38):cal 命令
原文网址:http://www.cnblogs.com/peida/archive/2012/12/14/2817473.html cal命令可以用来显示公历(阳历)日历.公历是现在国际通用的历法,又 ...
- FineUI 修改config表属性
此功能可用来设置系统的不同的标题 private void SelectSystem() { ConfigHelper.Title = DropDownList1.SelectedText; Conf ...
- 转 JMeter之修改Sampler响应数据的编码格式
问题:JMeter的sampler响应数据中有中文时,会解析出错. JMeter的Sampler中的响应数据默认的编码格式是:ISO-8859-1.来自文件: jmeter.properties中的语 ...