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 ...
随机推荐
- echarts 知识点
echarts map 禁止放大缩小,设置 calculable 为 false 即可. calculable: false echarts 报错: There is a chart instance ...
- 箭头函数中的 this
JS 每一个 function 都有自己独立的运行上下文,但箭头函数不属于普通的 function,所以没有独立的上下文. 所以在箭头函数里写的 this 其实是包含该箭头函数最近的一个 functi ...
- Oracle根据表的大小排序SQL语句
--按照数据行数排序select table_name,blocks,num_rows from dba_tables where owner not like '%SYS%' and table_n ...
- JFrame 与 Frame
JFrame是Frame的子类 Frame is part of java.awt package and exists since JDK1.0. JFrame is part of javax.s ...
- JZ2440 裸机驱动 第12章 I2C接口
本章目标: 了解I2C总线协议: 掌握S3C2410/S3C2440中I2C接口的使用方法: 12.1 I2C总线协议及硬件介绍 12.1.1 I2C总线协议 1 I2C总线的概念 2 I2C总线的信 ...
- [数据结构与算法] : AVL树
头文件 typedef int ElementType; #ifndef _AVLTREE_H_ #define _AVLTREE_H_ struct AvlNode; typedef struct ...
- 惠普(HP)战66 Pro G1 - 批量GHOST[Win10专业版 ] (UEFI)
笔记本型号:惠普(HP)战66 Pro G1 14英寸轻薄笔记本电脑(i5-8250U 8G 256G PCIe SSD+500G 标压MX150 2G独显)银色 需求: 公司一共采购10台笔记本,需 ...
- 关于android setTextSize() 以及 px dip/dp sp的说明。。。。
Paint.setTextSize()单位为px,Android系统中,默认的单位是像素(px).也就是说,在没有明确说明的情况下,所有的大小设置都是以像素为单位.Paint.setTextSize传 ...
- c# 与 java 语法异同
Java and C# ComparisonThis is a quick reference guide to highlight some key syntactical differences ...
- vue 之radio绑定v-model
示例: 单选radio <label ><input type="radio" value="0" v-model="branch& ...