- 博客(63)
- 收藏
- 关注
原创 53. Maximum Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [-2,1,-3,4,-1,2,1,-5,4],the contiguous subarray [4,-1,2,1]
2017-03-15 21:54:11 164
原创 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 sin
2017-03-14 16:32:59 173
原创 35. Search Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the arra
2017-03-14 15:36:51 122
原创 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 as001110
2017-03-14 11:50:26 263
原创 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 theHamming weight).For example, the 32-bit integer ’11' has binary representation 00000
2017-03-14 11:48:18 132
原创 405. Convert a Number to Hexadecimal
Given an integer, write an algorithm to convert it to hexadecimal. For negative integer,two’s complement method is used.Note: All letters in hexadecimal (a-f) must be in lowercase.The he
2017-03-14 11:34:38 165
原创 238. Product of Array Except Self
Given an array of n integers where n > 1, nums, return an arrayoutput such that output[i] is equal to the product of all the elements ofnums except nums[i].Solve it without division and in O
2017-03-11 15:14:10 124
原创 442. Find All Duplicates in an Array
Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appeartwice and others appear once.Find all the elements that appear twice in this array.Could you do it without e
2017-03-11 14:24:53 138
原创 338. Counting Bits
Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representation and return them as an array.Example:For num
2017-03-11 14:06:48 129
原创 342. Power of Four
Given an integer (signed 32 bits), write a function to check whether it is a power of 4.Example:Given num = 16, return true. Given num = 5, return false. Follow up: Could you solve it withou
2017-03-10 18:10:24 160
原创 231. Power of Two
Given an integer, write a function to determine if it is a power of two. public class Solution { public boolean isPowerOfTwo(int n) { if(n<0) return false; if(Int
2017-03-10 15:31:50 193
原创 326. Power of Three
Given an integer, write a function to determine if it is a power of three.Follow up:Could you do it without using any loop / recursion? 递归:public class Solution { public static boolean
2017-03-10 12:14:54 137
原创 219. Contains Duplicate II
Given an array of integers and an integer k, find out whether there are two distinct indicesi and j in the array such that nums[i] = nums[j] and theabsolute difference between i and j is at mo
2017-03-09 17:38:00 179
原创 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 elemen
2017-03-09 17:25:22 156
原创 401. Binary Watch
A binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom represent theminutes (0-59).Each LED represents a zero or one, with the least significant bi
2017-03-09 16:59:39 130
原创 409. Longest Palindrome
Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters.This is case sensitive, for example "Aa" is not c
2017-03-08 21:19:54 157
原创 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
2017-03-08 21:01:10 124
原创 268. Missing Number
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.For example,Given nums = [0, 1, 3] return 2. Note:Your algorithm should
2017-03-07 18:30:28 138
原创 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 squar
2017-03-07 11:28:07 148
原创 58. Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A word is
2017-03-06 22:52:35 157
原创 1. Two Sum
public class Solution { public int[] twoSum(int[] nums, int target) { int len=nums.length; if(nums==null||len==0) return null; int s=0; int[] res=ne
2017-03-06 21:19:14 110
原创 7. Reverse Integer
public int reverse(int x) { long res=0; while(x!=0) { res=res*10+x%10; x=x/10; } if (res>Integer.MAX_VALUE||res<Integer.MIN_VAL
2017-03-05 23:45:58 117
原创 168. Excel Sheet Column Title
Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB public class Solution { publ
2017-03-05 21:24:49 126
原创 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 ->
2017-03-05 21:23:10 133
原创 169. Majority Element
Given an array of size n, find the majority element. The majority element is the element that appearsmore than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element
2017-03-04 16:20:24 145
原创 383. Ransom Note
Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the ransom note can be constructed from the magazines
2017-03-04 15:39:30 212
原创 504. Base 7
Given an integer, return its base 7 string representation.Example 1:Input: 100Output: "202"Example 2:Input: -7Output: "-10"Note: The input will be in range of [-1e7, 1e7]. public c
2017-03-04 12:00:22 111
原创 455. Assign Cookies
Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a greed factor gi, which is the minimum size of a
2017-03-04 11:43:01 186
原创 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 you
2017-03-04 11:07:21 124
原创 506. Relative Ranks
Given scores of N athletes, find their relative ranks and the people with the top three highest scores, who will be awarded medals: "Gold Medal", "Silver Medal" and "Bronze Medal".Example 1:In
2017-03-03 22:29:24 152
原创 492. Construct the Rectangle
For a web developer, it is very important to know how to design a web page's size. So, given a specific rectangular web page’s area, your job by now is to design a rectangular web page, whose leng
2017-03-03 21:48:58 116
原创 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
2017-03-03 15:38:44 101
原创 100. Same Tree
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value./** * D
2017-02-28 22:26:53 117
原创 520. Detect Capital
Given a word, you need to judge whether the usage of capitals in it is right or not.We define the usage of capitals in a word to be right when one of the following cases holds:All letters
2017-02-28 22:02:41 125
原创 404. Sum of Left Leaves
Find the sum of all left leaves in a given binary tree.Example: 3 / \ 9 20 / \ 15 7There are two left leaves in the binary tree, with values 9 and 15 respectively. Return
2017-02-28 21:26:35 120
原创 415. Add Strings
Given two non-negative integers num1 and num2 represented as string, return the sum ofnum1 and num2.Note: The length of both num1 and num2 is Both num1 and num2 contains only digits 0-9.Bo
2017-02-27 22:02:57 110
原创 387. First Unique Character in a String
Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1.Examples:s = "leetcode"return 0.s = "loveleetcode",return 2.public class Solu
2017-02-27 21:04:24 105
原创 226. Invert Binary Tree
Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1/** * Definition for a binary tree node. * public class TreeNode { *
2017-02-27 20:39:00 117
原创 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
2017-02-24 17:08:39 121
原创 389. Find the Difference
Given two strings s and t which consist of only lowercase letters.String t is generated by random shuffling string s and then add one more letter at a random position.Find the letter that was ad
2017-02-24 16:54:44 145
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人