- 博客(69)
- 收藏
- 关注
原创 [LeetCode]143. Reorder List
Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For example,Given {1,2,3,4}, reorder it to
2015-05-28 07:34:28
275
原创 [LeetCode]203. Remove Linked List Elements
Remove all elements from a linked list of integers that have value val.ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2 --> 3 --> 4 --> 5Solution: 使用指针,注意头结点,涉及到链表
2015-05-20 08:35:05
307
原创 [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-05-20 08:27:26
458
原创 [LeetCode]206. Reverse Linked List
Reverse a singly linked list.Solution: 创建before, cur, after指针。Time Complexity: O(n)Solution1: Recursive# Definition for singly-linked list.# class ListNode:# def __init__(self, x):#
2015-05-09 05:11:16
867
原创 [LeetCode] 204. Count Primes
Description:Count the number of prime numbers less than a non-negative number, nSolution 1:create a dict to store the number of prime less than n.Time Complexity: O(n*n)class Solut
2015-05-02 08:06:41
552
原创 [LeetCode] 205. Isomorphic Strings
Given two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to get t.All occurrences of a character must be replaced with anot
2015-05-02 06:36:53
783
原创 [LeetCode]187. Repeated DNA Sequences
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DNA.Wri
2015-04-22 07:48:15
260
原创 [LeetCode]198. House Robber
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent house
2015-04-02 09:29:12
386
原创 [LeetCode]067. Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".Solution: string manipulation, pay attention to "carry"Running Time: O(n)
2015-03-31 14:27:24
322
原创 [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 as0011100101
2015-03-31 10:17:58
270
原创 [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].Note:Try to come up as many solutions as yo
2015-03-31 09:27:08
402
原创 [LeetCode]004. Median of Two Sorted Arrays
There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).Note:median: 中位数1. 对于奇数长度的数
2015-03-19 16:54:01
264
原创 [LeetCode]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
2015-02-16 06:20:51
196
原创 [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-02-16 06:16:19
305
原创 [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?经典DP问题:可以参考http://www.cs
2015-02-16 06:07:26
337
原创 [LeetCode]83. Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3.Solution: 遍历数组Running T
2015-02-16 05:58:48
283
原创 [LeetCode]111. Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node# Definition for a binary tree n
2015-01-30 18:56:16
295
原创 [Leetcode] 112. Path Sum
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary tree and sum
2015-01-30 18:51:22
255
原创 [LeetCode] 119. Pascal's Triangle II
Given 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?Solution:Run
2015-01-28 20:48:10
293
原创 [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]]Solution:杨辉三角,result[i][j]
2015-01-28 20:41:38
286
原创 [LeetCode] 160. Intersection of Two Linked Lists
Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a1 → a2 ↘
2015-01-26 09:28:07
270
原创 [LeetCode] 88. Merge Sorted Array
Given two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space (size that is greater or equal to m + n) to hold additional elements fro
2015-01-25 15:45:32
309
原创 [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
2015-01-24 20:31:24
325
原创 [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 ...
2015-01-24 20:27:57
427
原创 [LeetCode] 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 Solutio
2015-01-24 20:24:27
480
原创 [LeetCode] 165. Compare Version Numbers
Compare Version NumbersCompare two version numbers version1 and version1.If version1 > version2 return 1, if version1 version2 return -1, otherwise return 0.You may assume that t
2015-01-24 20:16:24
303
原创 [LeetCode] 155. Min Stack
Min StackDesign a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stac
2015-01-24 20:06:27
307
原创 [LeetCode]Evaluate Reverse Polish Notation
Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expression.Some examples: ["2", "1",
2014-10-24 14:42:33
320
原创 [LeetCode]Reverse Words in a String
Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".click to show clarification.Clarification:What constitutes
2014-10-24 14:35:00
398
原创 [LeetCode] Find Minimum in Rotated Sorted Array II
Follow up for "Find Minimum in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Suppose a sorted array is rotated at some pivot unk
2014-10-24 14:13:54
1160
原创 [LeetCode]Find Minimum in Rotated Sorted Array
Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).Find the minimum element.You may assume no duplicate exists in
2014-10-24 13:46:31
509
原创 [LeetCode] Maximum Product Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array [2,3,-2,4],the contiguous subarray [2,3] has the largest
2014-10-16 09:37:58
355
原创 [LeetCode]039. Combination Sum
Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen from C unlimited numb
2013-10-14 09:46:10
395
原创 [LeetCode]038. Count and Say
The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11.11 is read off as "two 1s" or 21.21 is read off as
2013-10-11 12:19:37
597
原创 [LeetCode]037. Sudoku Solver
Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character '.'.You may assume that there will be only one unique solution.A sudoku
2013-10-11 09:53:32
468
原创 [LeetCode]036. Valid Sudoku
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character '.'.A partially fille
2013-10-07 14:43:29
376
原创 [LeetCode]035. 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 array.
2013-10-07 09:41:42
410
原创 [LeetCode]034. Search for a Range
Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the target is not found
2013-10-07 08:48:03
482
原创 [LeetCode]033. Search in Rotated Sorted Array
Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If found in the array retur
2013-10-06 15:47:08
362
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人