- 博客(46)
- 收藏
- 关注
原创 Leetcode: Interleaving String
Problem:Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example,Given:s1 = "aabcc",s2 = "dbbca",When s3 = "aadbbcbcac", return true.When s3 = "aa
2015-03-17 05:51:26
442
原创 Leetcode: Subsets
Problem:Given a set of distinct integers, S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.
2015-03-14 01:31:02
529
原创 Leetcode: Climbing Stairs
Problem: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?Solution:
2015-03-13 10:55:31
483
原创 Leetcode: Rotate List
Problem: Given a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL.Solution:
2015-03-11 02:19:20
373
原创 Leetcode: Length of Last Word
Problem: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.N
2015-02-27 05:13:12
411
原创 Leetcode: Insert Interval
Problem:Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their sta
2015-02-27 04:59:23
414
原创 Leetcode: spiral Matrix II.
Problem:Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.For example,Given n = 3,You should return the following matrix:[ [ 1, 2, 3 ], [
2015-02-27 04:41:53
424
原创 Leetcode: Spiral Matrix
Problem:Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7,
2015-02-27 01:36:32
361
原创 Leetcode: N-Queens && N-Queens II
N-Queens:Problem:The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solut
2015-02-25 09:39:10
499
原创 Leetcode:Wildcard Matching
Problem:'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequence).The matching should cover the entire input string (not partial).The function pro
2015-02-23 04:38:36
427
原创 Leetcode: Multiply Strings
Problem:Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-negative.Solution:multiply
2015-02-22 12:16:03
616
原创 Leetcode: Trapping Rain Water
Problem:Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example, Given [0,1,0,2,1,
2015-02-22 11:33:42
713
原创 Leetcode: First Missing Positive
Problem:Given an unsorted integer array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm should run in O(n) time and
2015-02-22 10:57:41
399
原创 Leetcode: Combination Sum II
Problem:Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums toT.Each number in C may only be used once i
2015-02-22 10:41:38
466
原创 Leetcode: Combination Sum
Problem: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
2015-02-22 10:24:11
364
原创 Leetcode: Count and Say
Problem: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 i
2015-02-22 07:31:14
412
原创 Leetcode: Implement strStr()
Problem:Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Update (2014-11-02):The signature of the function ha
2015-02-19 09:41:17
553
原创 Leetcode: Remove Element
Problem: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 ne
2015-02-19 08:53:37
472
原创 Leetcode: Remove Duplicates from Sorted Array
Problem: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
2015-02-19 08:13:33
404
原创 Leetcode: Reverse Nodes in k-Group
Problem:Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k then left-out nodes in the end should r
2015-02-19 07:29:38
449
原创 Leetcode: Generate Parentheses
Problem: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:"((()))", "(()())", "(())()", "
2015-02-18 10:57:45
400
原创 Leetcode: Valid Parentheses
Problem:Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}
2015-02-18 08:54:04
370
原创 Leetcode: Remove Nth Node From End of List
Problem:Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node fro
2015-02-18 07:52:48
452
原创 Leetcode:Letter Combinations of a Phone Number
Problem: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.
2015-02-18 07:09:19
473
原创 Leetcode: 4Sum
Problem: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
2015-02-18 06:24:37
363
原创 Leetcode: 3Sum Closest
Problem: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 woul
2015-02-16 11:54:03
348
原创 Leetcode: 3Sum
Problem: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:Elements in a
2015-02-16 10:35:05
305
原创 Leetcode: Longest Common Prefix
Problem:Write a function to find the longest common prefix string amongst an array of strings.Solution: Idea: compare each character of all the strings.Code:public cl
2015-02-16 10:24:14
360
原创 Leetcode: Regular Expression Matching 这道每次都要看答案 心塞 啊啊啊
Problem:Implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the e
2015-02-15 09:10:16
676
原创 Learning PHP (1) install XAMPP, HelloWorld (Mac)
PHP: Hypertext PreprocessorSetup: php code is usually embedded in HTML files or in its own php file.Code: delimiters: content php>The website for downloading XAMPP(Apache + MySQL +PH
2015-02-14 02:19:04
570
原创 Leetcode: Add Two Numbers
Problem:You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and retur
2015-02-13 12:01:43
442
原创 Leetcode: Longest Substring Without Repeating Characters
Problem:Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is
2015-02-13 08:11:35
403
原创 Leetcode: Two Sum
Problem:Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the
2015-02-12 12:00:00
410
原创 Leetcode: Construct Binary Tree from Preorder and Inorder Traversal
Problem:Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.Solution:My code:/** * D
2015-02-03 12:19:04
377
原创 Leetcode: Balanced Binary Tree
Problem:Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every no
2015-02-03 12:12:28
335
原创 Leetcode: Binary Tree Preorder Traversal
Problem:Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,2,3].Note: Re
2015-01-29 10:42:48
350
原创 Path Sum II
Problem:Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree and sum = 22, 5
2015-01-28 08:43:32
490
原创 Leetcode: Path Sum
Problem: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
2015-01-28 08:19:30
363
原创 Leetcode: Populating Next Right Pointers in Each Node II
Problem:Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution still work?Note:You may only
2015-01-28 07:57:25
481
原创 Leetcode: Populating Next Right Pointers in Each Node
Problem:Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its nex
2015-01-28 07:19:13
340
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅