LeetCode - PlusOne
题意:给一个数按位存放在一个int数组中,要求返回这个数加一后的数组。
懒人解法:
public class Solution {
public int[] plusOne(int[] digits) {
java.math.BigInteger Bigdigits = new java.math.BigInteger(toString(digits));
String s = Bigdigits.add(new java.math.BigInteger("1")).toString();
return toArray(s);
}
public static String toString(int[] d) {
StringBuilder sb = new StringBuilder();
for(int i=0; i<d.length; i++) {
sb.append(d[i]);
}
return sb.toString();
}
public static int[] toArray(String s) {
int[] ans = new int[s.length()];
for(int i=0; i<s.length(); i++) {
ans[i] = s.charAt(i) - '0';
}
return ans;
}
}
LeetCode - PlusOne的更多相关文章
- leetcode — plus-one
import java.util.ArrayList; import java.util.Arrays; import java.util.List; /** * Source : https://o ...
- [LeetCode 题解]: plusOne
前言 [LeetCode 题解]系列传送门: http://www.cnblogs.com/double-win/category/573499.html 1.题目描述 Given a no ...
- [LeetCode] Plus One Linked List 链表加一运算
Given a non-negative number represented as a singly linked list of digits, plus one to the number. T ...
- [LeetCode] Plus One 加一运算
Given a non-negative number represented as an array of digits, plus one to the number. The digits ar ...
- Leetcode分类刷题答案&心得
Array 448.找出数组中所有消失的数 要求:整型数组取值为 1 ≤ a[i] ≤ n,n是数组大小,一些元素重复出现,找出[1,n]中没出现的数,实现时时间复杂度为O(n),并不占额外空间 思路 ...
- leetcode算法分类
利用堆栈:http://oj.leetcode.com/problems/evaluate-reverse-polish-notation/http://oj.leetcode.com/problem ...
- LeetCode Plus One Linked List
原题链接在这里:https://leetcode.com/problems/plus-one-linked-list/ 题目: Given a non-negative number represen ...
- leetcode bugfree note
463. Island Perimeterhttps://leetcode.com/problems/island-perimeter/就是逐一遍历所有的cell,用分离的cell总的的边数减去重叠的 ...
- LeetCode题目分类
利用堆栈:http://oj.leetcode.com/problems/evaluate-reverse-polish-notation/http://oj.leetcode.com/problem ...
随机推荐
- CentOS安装ssh服务
yum search ssh yum install openssh-server service sshd status [编辑]艺搜参考 http://www.cnblogs.com/eastso ...
- 【学习笔记】jQuery中的动画与效果
1.基本效果 匹配元素从左上角开始变浓变大或缩小到左上角变淡变小 ①隐藏元素 除了可以设置匹配元素的display:none外,可以用以下函数 hide(speed,[callback]) 返回值: ...
- [oracle] oracle-myibatis-整理
==================================== insert ========================================== 语句 <insert ...
- 跑在Docker下的RHEL7编译Java8源码包
1.运行Docker时需要加参数--cap-add=SYS_PTRACE,比如: docker run --cap-add=SYS_PTRACE --name buildjava8 -v /opt/r ...
- 获取表单提交MVC错误信息
if (!ModelState.IsValid) { List<string> Keys = ModelState.Ke ...
- selenium测试(Java)--执行JS(十八)
1. 操作滚动条 package com.test.js; import org.openqa.selenium.By; import org.openqa.selenium.Dimension; ...
- 手动安装OpenStack Mistral
Prepare packages: $ sudo apt-get install python-dev python-setuptools python-pip libffi-dev libxslt1 ...
- Java基础--生成验证码
HTML <%@ page language="java" contentType="text/html; charset=UTF-8" pageEnco ...
- Unity3d实现幸运转盘
完成效果 我说一下制作流程,然后再看后面的代码1.创建一个image,选择我们的转盘背景图,素材找我或者网上都有,不多说了哈:2.创建一个空物体,位于转盘的正中心,因为我们的转盘指针的旋转中心是根据空 ...
- day06<面向对象>
面向对象(面向对象思想概述) 面向对象(类与对象概述) 面向对象(学生类的定义) 面向对象(手机类的定义) 面向对象(学生类的使用) 面向对象(手机类的使用) 面向对象(一个对象的内存图) 面向对象( ...