- 博客(98)
- 收藏
- 关注
原创 【LeetCode】 029. Divide Two Integers
Divide two integers without using multiplication, division and mod operator. If it is overflow, return MAX_INT. public class Solution { public int divide(int dividend, int divisor) {
2016-12-29 19:56:36 125
原创 【LeetCode】 022. Generate Parentheses
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: [ "((()))", "(()())", "(())()", "()(())
2016-12-29 06:13:41 188
原创 【LeetCode】 018. 4Sum
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target. Note: The solution
2016-12-29 05:54:30 315
原创 【LeetCode】 017. Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent. A mapping of digit to letters (just like on the telephone buttons) is given below. Input:Digit st
2016-12-28 22:47:11 240
原创 【LeetCode】 016. 3Sum Closest
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exact
2016-12-28 12:26:48 134
原创 【LeetCode】 015. 3Sum
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero. Note: The solution set must not contain
2016-12-28 10:33:25 145
原创 【LeetCode】 011. Container With Most Water
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Fin
2016-12-28 09:53:14 137
原创 【LeetCode】 005. Longest Palindromic Substring
Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. Example: Input: "babad" Output: "bab" Note: "aba" is also a valid answer.
2016-12-28 07:57:39 147
原创 【LeetCode】 475. Heaters
Winter is coming! Your first job during the contest is to design a standard heater with fixed warm radius to warm all the houses. Now, you are given positions of houses and heaters on a horizontal
2016-12-28 03:24:51 346
原创 【LeetCode】 463. Island Perimeter
You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is completely
2016-12-27 23:09:43 191
原创 【LeetCode】 461. Hamming Distance
The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Given two integers x and y, calculate the Hamming distance. Note: 0 ≤ x,
2016-12-27 23:08:35 227
原创 【LeetCode】 459. Repeated Substring Pattern
Given a non-empty string check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. You may assume the given string consists of lowercase Engli
2016-12-27 23:07:34 188
原创 【LeetCode】 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 c
2016-12-27 23:06:30 159
原创 【LeetCode】 453. Minimum Moves to Equal Array Elements
Given a non-empty integer array of size n, find the minimum number of moves required to make all array elements equal, where a move is incrementing n - 1 elements by 1. Example: Input: [1,2,3] Ou
2016-12-27 11:59:13 243
原创 【LeetCode】 448. Find All Numbers Disappeared in an Array
Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once. Find all the elements of [1, n] inclusive that do not appear in this array.
2016-12-27 11:32:53 153
原创 【LeetCode】 447. Number of Boomerangs
Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of points (i, j, k) such that the distance between i andj equals the distance between i and k (the order of t
2016-12-26 23:10:48 159
原创 【LeetCode】 441. Arranging Coins
You have a total of n coins that you want to form in a staircase shape, where every k-th row must have exactly k coins. Given n, find the total number of full staircase rows that can be formed.
2016-12-26 22:06:30 133
原创 【LeetCode】 438. Find All Anagrams in a String
Given a string s and a non-empty string p, find all the start indices of p's anagrams in s. Strings consists of lowercase English letters only and the length of both strings s and p will not be lar
2016-12-26 13:58:47 156
原创 【LeetCode】 437. Path Sum III
You are given a binary tree in which each node contains an integer value. Find the number of paths that sum to a given value. The path does not need to start or end at the root or a leaf, but it
2016-12-26 05:30:55 165
原创 【LeetCode】 434. Number of Segments in a String
Count the number of segments in a string, where a segment is defined to be a contiguous sequence of non-space characters. Please note that the string does not contain any non-printable characters.
2016-12-25 12:59:06 149
原创 【LeetCode】 415. Add Strings
Given two non-negative numbers num1 and num2 represented as string, return the sum of num1 and num2. Note: The length of both num1 and num2 is Both num1 and num2 contains only digits 0-9.B
2016-12-25 12:30:24 172
原创 【LeetCode】 414. Third Maximum Number
Given a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The time complexity must be in O(n). Example 1: Input: [3, 2,
2016-12-25 07:48:24 188
原创 【LeetCode】 412. Fizz Buzz
Write a program that outputs the string representation of numbers from 1 to n. But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”.
2016-12-25 06:01:49 166
原创 【LeetCode】 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 con
2016-12-25 05:47:45 145
原创 【LeetCode】 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 hexade
2016-12-25 05:37:51 191
原创 【LeetCode】 404. Sum of Left Leaves
Find the sum of all left leaves in a given binary tree. Example: 3 / \ 9 20 / \ 15 7 There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24
2016-12-25 04:24:05 140
原创 【LeetCode】 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 the minutes (0-59). Each LED represents a zero or one, with the least significant bit o
2016-12-25 04:15:55 144
原创 【LeetCode】 400. Nth Digit
Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... Note: n is positive and will fit within the range of a 32-bit signed integer (n 31). Example 1: Input
2016-12-25 02:10:04 200
原创 【LeetCode】 396. Rotate Function
Given an array of integers A and let n to be its length. Assume Bk to be an array obtained by rotating the array A k positions clock-wise, we define a "rotation function" F on A as follow:
2016-12-25 01:14:29 160
原创 【LeetCode】 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
2016-12-25 00:34:49 144
原创 【LeetCode】 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. Note:
2016-12-25 00:20:01 127
原创 【LeetCode】 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 ; ot
2016-12-25 00:09:58 142
原创 【LeetCode】 374. Guess Number Higher or Lower
We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to guess which number I picked. Every time you guess wrong, I'll tell you whether the number is h
2016-12-24 23:37:25 136
原创 【LeetCode】 371. Sum of Two Integers
Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Example: Given a = 1 and b = 2, return 3. public class Solution { public int getSum(int a, in
2016-12-24 23:22:59 126
原创 【LeetCode】 350. Intersection of Two Arrays II
Given two arrays, write a function to compute their intersection. Example: Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2, 2]. Note: Each element in the result should appear as ma
2016-12-24 22:02:47 134
原创 【LeetCode】 349. Intersection of Two Arrays
Given two arrays, write a function to compute their intersection. Example: Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2]. Note: Each element in the result must be unique.The res
2016-12-24 21:33:07 130
原创 【LeetCode】 345. Reverse Vowels of a String
Write a function that takes a string as input and reverse only the vowels of a string. Example 1: Given s = "hello", return "holle". Example 2: Given s = "leetcode", return "leotcede". Note
2016-12-24 14:34:49 337
原创 【LeetCode】 344. Reverse String
Write a function that takes a string as input and returns the string reversed. Example: Given s = "hello", return "olleh". public class Solution { public String reverseString(String s)
2016-12-24 13:38:17 132
原创 【LeetCode】 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 without
2016-12-24 13:28:05 116
原创 【LeetCode】 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 boolean isPowerOfThr
2016-12-24 13:19:53 115
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人