自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(27)
  • 收藏
  • 关注

原创 【LeetCode】172. Factorial Trailing Zeroes

Given an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity.Method 2 is original by myself. It is very close to Method 1, i need think mo

2015-12-19 18:24:08 348

原创 【LeetCode】67 Add Binary

Given two binary strings, return their sum (also a binary string).For example, a = “11” b = “1” Return “100”.Summary: Array[i] is faster than String.charAt(int i);Method 1 : (4ms)public class S

2015-12-04 17:59:29 396

原创 【LeetCode】219 Contains Duplicate II

Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between i and j is at most k.public clas

2015-12-04 16:28:27 294

原创 【LeetCode】88 Merge Sorted Array

Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note: You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional

2015-12-03 17:06:24 242

原创 【LeetCode】119 Pascal's Triangle II

Pascal’s TriangleGiven an index k, return the kth row of the Pascal’s triangle.For example, given k = 3, Return [1,3,3,1].Note: Could you optimize your algorithm to use only O(k) extra space?Method 1

2015-12-03 13:58:21 344

原创 【LeetCode】118 Pascal's Triangle

Given numRows, generate the first numRows of Pascal’s triangle.For example, given numRows = 5, Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ]public class Solution { pub

2015-12-03 10:49:18 234

原创 【LeetCode】27 Remove Element

Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn’t matter what you leave beyond the new length.Method 1:(

2015-12-03 09:49:03 240

原创 【LeetCode】190 Reverse Bits

Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 00111001011110

2015-12-03 09:45:23 246

原创 【LeetCode】190 Reverse Bits

Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 00111001011110

2015-12-02 14:37:44 222

原创 【LeetCode】189 Rotate Array

Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].Congradulation! My runtime beats 98.27% of java submissi

2015-12-02 13:21:14 237

原创 【LeetCode】66 Plus One

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.题意:给定一个非负整数用数组形式表示,最高位在数组下标最低

2015-12-02 09:27:03 242

原创 【LeetCode】26 Remove Duplicates from Sorted Array

Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place with cons

2015-12-01 18:13:37 276

原创 【LeetCode】228 Summary Ranges

Given a sorted integer array without duplicates, return the summary of its ranges.For example, given [0,1,2,4,5,7], return [“0->2”,”4->5”,”7”].public class Solution { public List<String> summaryRan

2015-12-01 17:39:55 217

原创 【LeetCode】231 Power of Two

Given an integer, write a function to determine if it is a power of two.思路: 求是否是2的幂,由2可以联想到2进制,只要数的2进制表示中只含有一个值为1的bit位,这个数即是2的幂。 法2用Integer.bitCount(int i)方法,该方法虽然只需一行即可解决问题,但是所需的时间却比自己写的法1更多

2015-12-01 17:11:48 323

原创 【LeetCode】231 Power of Two

Given an integer, write a function to determine if it is a power of two.思路: 求是否是2的幂,由2可以联想到2进制,只要数的2进制表示中只含有一个值为1的bit位,这个数即是2的幂。 法2用Integer.bitCount(int i)方法,该方法虽然只需一行即可解决问题,但是所需的时间却比自己写的法1更多

2015-12-01 17:11:20 207

原创 【LeetCode】202 Happy Number

Write an algorithm to determine if a number is "happy". A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares

2015-12-01 16:12:47 273

原创 【LeetCode】263 Ugly Number

Write a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly since it in

2015-12-01 14:37:53 236

原创 【LeetCode】70 Climbing Stairs

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?public class Solution { public in

2015-12-01 13:59:31 231

原创 【LeetCode】13 Roman to Integer

Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.public class Solution { public int romanToInt(String s) { char[] arrs = s.toCharArr

2015-12-01 13:50:46 240

原创 【LeetCode】191 Number of 1 Bits

Write a function that takes an unsigned integer and returns the number of ’1’ bits it has (also known as the Hamming weight).For example, the 32-bit integer ’11’ has binary representation 0000000000000

2015-12-01 13:42:21 259

原创 【LeetCode】169 Majority Element

Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element always

2015-12-01 13:37:57 305

原创 【LeetCode】171 Excel Sheet Column Number

Related to question Excel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example:A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 publ

2015-12-01 13:36:17 267

原创 【LeetCode】242 Valid Anagram

Given two strings s and t, write a function to determine if t is an anagram of s.For example, s = “anagram”, t = “nagaram”, return true. s = “rat”, t = “car”, return false.Note: You may assume the s

2015-12-01 13:35:16 270

原创 【LeetCode】217 Contains Duplicate

Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element is

2015-12-01 13:33:01 292

原创 【LeetCode】283 Move Zeroes

Given an array nums, write a function to move all 0’s to the end of it while maintaining the relative order of the non-zero elements.For example, given nums = [0, 1, 0, 3, 12], after calling your funct

2015-12-01 13:29:54 262

原创 【LeetCode】258. Add Digits

Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one digit, r

2015-12-01 12:00:52 330

原创 【LeetCode】292.Nim Game

You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will be the

2015-12-01 11:53:26 322

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除