- 博客(35)
- 资源 (2)
- 收藏
- 关注
原创 LeetCode:Interleaving String
Given s1, s2, s3, find whether s3 is formed by the interleaving ofs1 and s2. For example,Given:s1 = "aabcc",s2 = "dbbca", When s3 = "aadbbcbcac", return true.When s3 = "aadbbbaccc", retu
2014-06-30 15:45:17 334
原创 LeetCode:Regular Expression Matching
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 entire input st
2014-06-22 19:43:13 408
原创 LeetCode:Jump Game I && II
Jump Game Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that positi
2014-06-19 23:40:09 327
原创 LeetCode: 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:"((()))", "(()())", "(())()", "()(())", "()()
2014-06-18 22:24:18 358
原创 LeetCode:Longest Consecutive Sequence
Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given [100, 4, 200, 1, 3, 2],The longest consecutive elements sequence is [1, 2, 3
2014-04-29 14:17:16 489
原创 LeetCode:Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.
2014-04-29 13:56:15 394
原创 LeetCode: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, and there exists one unique longest palindromic substring.
2014-04-16 16:43:12 356
原创 LeetCode:Insert Interval
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 start times.E
2014-04-09 11:46:26 329
原创 LeetCode:Trapping Rain Water
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,0,1,3,2,1,2,1]
2014-04-09 10:08:50 407
原创 LeetCode:Path Sum I &&II
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
2014-04-03 16:13:53 436
原创 LeetCode:Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.有序数列化为二叉搜索树,经典算法,找到中间节点作为root,依次递归下去,直到构建成为二叉搜索树。/** * Definition for binary tree * public class
2014-04-03 10:02:52 467
原创 LeetCode: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 from
2014-03-28 20:39:41 474
原创 LeetCode: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]]生成杨辉三角,一行中除了两边的数字为1以外,该数等于
2014-03-28 20:18:40 392
原创 LeetCode:Balanced Binary Tree
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 node never diffe
2014-03-28 17:53:11 327
原创 LeetCode:Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. Y
2014-03-28 17:34:14 306
原创 LeetCode:Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3But the f
2014-03-28 17:23:14 417
原创 LeetCode:Merge Two Sorted Lists
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.合并有序链表,为避免对head进行讨论,建立一个空head,返回的时候返回head.next,建立空head之
2014-03-28 17:12:27 322
原创 LeetCode:Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.由于是有序表,直接递归生成。/** * Definition for binary tree * public class TreeNode { * int val; * T
2014-03-28 16:57:25 312
原创 LeetCode:Rotate List
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.首先计算链表长度,将链表首尾相接,之后得出链表从head开始起的正
2014-03-28 16:51:29 333
原创 LeetCode: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] ha
2014-03-27 22:29:06 306
原创 LeetCode: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?典型的斐波拉契数列,简单的动态规划问题,开始的时候想到f
2014-03-27 21:41:59 278
原创 LeetCode: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.删除有序链表中重复的数值,一次遍历,设置指针指
2014-03-27 21:32:39 329
原创 LeetCode: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
2014-03-27 21:20:46 284
原创 LeetCode:Populating Next Right Pointers in Each Node I & II
Populating Next Right Pointers in Each NodeGiven a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Popul
2014-03-27 21:09:49 368
原创 LeetCode:Linked List Cycle I & II
Linked List CycleGiven a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?判断链表是否有环,经典的做法就是设快慢指针各一个,当快指针和慢指针重合时说明链接有环,否则快指针将为null。
2014-03-27 19:30:02 451
原创 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-03-27 19:05:09 422
原创 LeetCode:Simplify Path
Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"题目不难,利用正则表达式以"/"为分隔符进行分割,将"",".",".."的其他所有字符串压栈,碰到一次".."将栈
2014-03-27 18:55:24 301
原创 LeetCode:Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321记录正负号,将数组转为无符号并转为字符串,之后翻转字符,最后再把正负号加上。public class Solution { public int reverse(int x) {
2014-03-27 14:38:30 294
原创 LeetCode:Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.求二叉树的深度,递归得到结果。/** * Definiti
2014-03-27 14:34:50 233
原创 LeetCode:Unique Binary Search Trees
Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1
2014-03-27 14:31:23 234
原创 LeetCode:Best Time to Buy and Sell Stock I & II & III
Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock),
2014-03-27 14:24:32 360
原创 LeetCode:Single Number I && II
Given an array of integers, every element appears twice except for one. Find that single one.题目很直接,直接建哈希表,遍历,在表中就删除元素,不在表中就加入表,最后表中只剩下一个元素,返回其值:public class Solution { public int singleNum
2014-03-27 13:00:54 496
原创 LeetCode:Subsets I
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.For examp
2014-03-27 11:50:33 440
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人