LeetCode----66. Plus One(Java)
package plusOne66;
/*
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.
*/
public class Solution { public static int[] plusOne(int[] digits) {
int index=digits.length-1;
digits[index]=digits[index]+1;
while(digits[index]>=10&&index>0){
digits[index]=digits[index]%10;
index--;
digits[index]=digits[index]+1;
}
if (digits[0]>9)
{
digits[0]=digits[0]%10;
int[] result=new int[digits.length+1];
result[0]=1;
for (int i=0;i<digits.length;i++){
result[i+1]=digits[i];
}
return result;
}
return digits;
}
public static void main(String[] args) {
// TODO Auto-generated method stub int[] digits={9,9,9,9};
//System.out.println(plusOne(digits).toString());
} }
LeetCode----66. Plus One(Java)的更多相关文章
- LeetCode第[18]题(Java):4Sum 标签:Array
题目难度:Medium 题目: Given an array S of n integers, are there elements a, b, c, and d in S such that a + ...
- LeetCode第[1]题(Java):Two Sum 标签:Array
题目: Given an array of integers, return indices of the two numbers such that they add up to a specifi ...
- LeetCode第[46]题(Java):Permutations(求所有全排列) 含扩展——第[47]题Permutations 2
题目:求所有全排列 难度:Medium 题目内容: Given a collection of distinct integers, return all possible permutations. ...
- LeetCode第[1]题(Java):Two Sum (俩数和为目标数的下标)——EASY
题目: Given an array of integers, return indices of the two numbers such that they add up to a specifi ...
- 前端与算法 leetcode 66. 加一
目录 # 前端与算法 leetcode 66. 加一 题目描述 概要 提示 解析 解法一 解法二 算法 # 前端与算法 leetcode 66. 加一 题目描述 给定一个由整数组成的非空数组所表示的非 ...
- Java实现 LeetCode 66 加一
66. 加一 给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一. 最高位数字存放在数组的首位, 数组中每个元素只存储单个数字. 你可以假设除了整数 0 之外,这个整数不会以零开头. 示 ...
- Java [Leetcode 66]Plus One
题目描述: Given a non-negative number represented as an array of digits, plus one to the number. The dig ...
- [LeetCode]66.加一(Java)
原题地址: plus-one 题目描述: 给定一个由 整数 组成的 非空 数组所表示的非负整数,在该数的基础上加一. 最高位数字存放在数组的首位, 数组中每个元素只存储单个数字. 你可以假设除了整数 ...
- leetcode 刷题记录(java)-持续更新
最新更新时间 11:22:29 8. String to Integer (atoi) public static int myAtoi(String str) { // 1字符串非空判断 " ...
- LeetCode 66. Plus One(加1)
Given a non-negative integer represented as a non-empty array of digits, plus one to the integer. Yo ...
随机推荐
- Struts2中重定向和请求转发配置
struts2中默认跳转为dispatcher请求转发 只能往jsp转发,跳转action报404 重定向 设置为redirect ,可以是jsp也可以是action <!--同一个包下的act ...
- CentOS 7.0下配置MariaDB数据库
刚刚配置了下CentOS 7.0版本的服务器,配置数据库时发现# mysql_secure_installation命令用不了,之后网上查了一下发现CentOS 7.0版本用MariaDB替换了mys ...
- 由easyui的tab在ie下渲染失败,发现的一个有意义的问题
今天项目组的同事反映,在IE浏览器下,所有用easyui编写的tab控件都加载不出来,只会显示一个Loading的提示在控件的内容显示区. 刚分析这个问题,首先怀疑是使用easyui的tab的脚本写法 ...
- Java开发搜索引擎爬虫
package com.peidon.html; import java.io.BufferedReader; import java.io.File; import java.io.FileOutp ...
- jdbc中java与mysql数据类型的映射
注:这种类型匹配不是强制性标准,特定的JDBC厂商可能会改变这种类型匹配.例如Oracle中的DATE类型是包含时分秒,而java.sql.Date仅仅支持年月日.
- XML于JSON
XML:可拓展的标记语言(跨平台数据表现)用于保存数据 XML:标记需要关闭 :单根性 .NET中DOM常用对象: XmlDocument :一个XML文档 XmlNode:xml中的单个节点 Xml ...
- Android课程---课下练习(表格、线性和相对布局)
1.表格布局 练习代码: <?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns: ...
- response的Writer输出数据的问题
package cn.itcast.response; import java.io.IOException; import java.io.OutputStream; import java.io. ...
- 安装Arch Linux(桌面环境)
安装xorg-server # pacman -S xorg-server xorg-server-utils xorg-xinit 安装显卡驱动 如果不知道是什么显卡,就使用以下命令查看 # lsp ...
- 10与元素亲密接触:盒元素(the box model)
line-height属性可以设置文本的行间距,可以用像素.em或百分比等于字体大小有关的值定义行间距line-height: 1.6em;(行间距为字体大小的1.6倍) CSS把每一个单一的元素看作 ...