我的代码游记

归档 · 2016

首页

关于

归档

LeetCodeEasy数组大数运算

415.Add Strings(Easy)

Given two non-negative numbers num1 and num2 represented as string, return the sum of num1 and num2不解释了,就是大数相加 Note: 1.The length of both num1 and num2 is < 5100.2.Both num1 and num2 contains only digits 0-9.3.Both num1 and num2 does not contain any leading zero.4.You must not use any built-in BigInteger library or convert the inputs to integer direc..

更多
LeetCodeEasy数组大数运算

67.Add Binary(Easy)

Given two binary strings, return their sum (also a binary string).给两个二进制的字符串,返回它们的和 Example a = “11”b = “1”Return “100” My Solution(Java) Version 1 Time: 4ms:  这个其实没有太复杂的原理,基本上只要是字符串表示数都是大数运算的套路,先把字符串逆序,然后高位补0,然后用循环逐位相加,对进位的情况进行处理,然后就得到结果了,复杂的是进位的几种情况的处理 public class Solution { public String addBinary(String a, String b) { String..

更多
LeetCodeEasy字符串处理堆栈

345.Reverse Vowels of a String(Easy)

Write a function that takes a string as input and reverse only the vowels of a string.**Note:**The vowels does not include the letter “y”.写一个函数把字符串中的元音字母的顺序调转,‘Y’不是一个元音字母 Example 1: Given s = “hello”, return “holle”. Example 2: Given s = “leetcode”, return “leotcede”. My Solution(Java) Version 1 Time: 5ms:  先一次遍历把元音字母的下标记下来,然后把通过下标直接把字符串中的元音字母逆序,只需要..

更多
LeetCodeEasy递归

70.Climbing Stairs(Easy)

You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?你在爬楼梯,楼梯总共有n个台阶,每次你可爬一级或者两级台阶,问爬完整个楼梯有多少种爬的方式? *  这是以前小学的奥数题,找规律,爬楼梯,显然我们都知道对于一次只走一级或者两级的情况是符合斐波那契数列的,所以题目的答案就变成了求第n个斐波那契数是多少* My Solution(Java) Version 1 Time: 0ms:  应该是因为是Easy题,所以测试的样例相当少,求..

更多
1234