- 浏览: 173542 次
- 性别:
- 来自: 济南
文章分类
最新评论
Given a non-negative number represented as an array of digits, plus one to the number.
The digits are stored such that the most significant digit is at the head of the list.
这道题目和Add Binary 这道题,还有Add Two Numbers 这道题目属于同一类型的题目。主要的问题要维护一个进位carry,根据题目的要求,不管是二进制还是十进制,如果有进位,carry就为1。最后要检查最后一位是否有进位,如果有进位要重新设定数组的长度,来保存进位。代码如下:
The digits are stored such that the most significant digit is at the head of the list.
这道题目和Add Binary 这道题,还有Add Two Numbers 这道题目属于同一类型的题目。主要的问题要维护一个进位carry,根据题目的要求,不管是二进制还是十进制,如果有进位,carry就为1。最后要检查最后一位是否有进位,如果有进位要重新设定数组的长度,来保存进位。代码如下:
public class Solution { public int[] plusOne(int[] digits) { int carry = 0; for(int i = digits.length - 1; i >= 0; i--) { if(i == digits.length - 1) digits[i] ++; int tem = digits[i] + carry; if(tem > 9) { carry = 1; } else { carry = 0; } digits[i] = tem % 10; } if(carry == 1) { int[] result = new int[digits.length + 1]; result[0] = 1; return result; } return digits; } }
发表评论
-
498. Diagonal Traverse
2019-11-15 13:52 227Given a matrix of M x N eleme ... -
496 Next Greater Element I
2019-11-14 13:50 226You are given two arrays (witho ... -
Word Break II
2016-03-09 03:15 342Given a string s and a dictiona ... -
Insert Interval
2016-03-08 02:11 334Given a set of non-overlapping ... -
Merge Intervals
2016-03-07 05:25 451Given a collection of intervals ... -
Merge k Sorted Lists
2016-03-07 04:03 512Merge k sorted linked lists and ... -
Multiply Strings
2016-03-06 07:27 430Given two numbers represented a ... -
N-Queens II
2016-03-06 03:06 620Follow up for N-Queens problem. ... -
N-Queens
2016-03-06 02:47 428The n-queens puzzle is the prob ... -
First Missing Positive
2016-03-05 03:09 388Given an unsorted integer array ... -
Spiral Matrix
2016-03-04 03:39 519Given a matrix of m x n element ... -
Trapping Rain Water
2016-03-04 02:54 533Given n non-negative integers r ... -
Repeated DNA Sequences
2016-03-03 03:10 371All DNA is composed of a series ... -
Increasing Triplet Subsequence
2016-03-02 02:48 861Given an unsorted array return ... -
Maximum Product of Word Lengths
2016-03-02 01:56 883Given a string array words, fin ... -
LRU Cache
2016-02-29 10:37 555Design and implement a data str ... -
Super Ugly Number
2016-02-29 07:07 601Write a program to find the nth ... -
Longest Increasing Path in a Matrix
2016-02-29 05:56 764Given an integer matrix, find t ... -
Coin Change
2016-02-29 04:39 736You are given coins of differen ... -
Minimum Height Trees
2016-02-29 04:11 629For a undirected graph with tre ...
相关推荐
plusOne代码
一个月挑战C++,里面的内容都很基础,是新手学习的很好的资料
OnePlus One Lux 插件。 OnePlus One 的 Lux 插件。
OnePlus One Bootlogo工具WIP OnePlus One Bootlogo工具
适用于Oneplus One的Ubuntu Touch ###如何安装: : ###如何建立: : ###什么在起作用? ###论坛: :
easyroot-opo Easy root for OnePlus one,适用于 linux 和 mac Start-new.sh = 用于新的引导加载程序(将擦除所有数据!)。 Start.sh = 用于旧的引导加载程序。 Start-new:-打开引导加载程序-Flash 新恢复(TWRP...
PlusOne Scraper从Google个人资料页面生成用户的PlusOne(+1)的RSS feed。 设计为自托管。 使用PHP和PHP Simple HTML DOM Paser构建。 代码也来自sgthayes。
OnePlusTouchFix 每次屏幕打开时,尝试重置(并希望修复)Oneplus One上的触摸。 这是通过运行命令来完成的 cat /sys/class/input/input0/baseline_test 每次获得意图ACTION_SCREEN_ON时,以root身份登录。
用于一加手机USB调试,刷机及第三方recovery可以使用OnePlus_USB_Drivers_Setup.exe
quicksupport和add-on(oneplus版) oneplus7pro 亲测可用,有问题或需要其他版本请私我
OnePlus 5 新品发布会,一加手机静态展示,一加手机性能介绍、工艺介绍、极简高大上设计,一加手机OnePlus 5 新品发布会ppt模板。
#README表示自述文件! 许可协议和免责声明版权所有(C)2014-2015 vvn [vvn @ notworth.it] This program is FREE software: you can redistribute it and/or modifyit as you wish. Copying and distribution of ...
One +的设备树版权所有2014,CyanogenMod项目
fer2013 plus 针对FER2013的图像,进行了10类投票(多了Contempt,unknown 和 非人脸三类),提供的是一种标签方式。采用最大投票方式,去除了一些不确定的图像。文档中含三个文件,Voted_labels.csv(自行下载)中是...
server.add('plusOne', function(value) { console.log(value 1); }); server.listen(9456); var kamote = require('kamote'); var client = new kamote.Client(); client.plusOne(100, ...
fastize-jit-prisma-findOne 12.4 5.77兆字节 fastify-prisma-findOne 13.4 6.24兆字节 fastify-prisma-jit-cache-select 2725.4 656兆字节 固定Prisma Jit选择 50 12兆字节 固定棱镜最小值 47.6 12.7兆字节...
OnePlus One(培根)的设备树 版权所有2014-2016,The CyanogenMod Project版权所有2017-2018,The LineageOS Project OnePlus One(代号为“培根” )是OnePlus的旗舰智能手机。 它于2014年6月发布。 基本的 规格...
适配所有的手机型号,操作简单,右击‘我的电脑’--管理--设备管理器--便携设备,然后双击,根据引导操作就行了
Yolk 是是构建异步用户界面的 JavaScript 库,... const count = plusOne.merge(minusOne).scan((x, y) => x y, 0).startWith(0) return ( id="plus" id="minus" 标签:Yolk
...The number of questions is increasing recently. Here is the classification of all `468` questions. ...I'll keep updating for full summary and better solutions....|-----|---------------- | --------------- |...