- 博客(42)
- 资源 (6)
- 收藏
- 关注
原创 二叉树的先序、中序、后序、层次遍历的递归和非递归解法
二叉树的先序、中序、后序、层次遍历的递归和非递归解法package tree;import java.util.LinkedList;import java.util.Queue;import java.util.Stack;public class TreeTraverse { /** * 先序递归 * @param root */ public stat
2014-09-05 15:30:25
883
原创 [LeetCode] Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.递归
2014-09-04 20:46:26
351
原创 [LeetCode] Next Permutation
Next Permutation Total Accepted: 14635 Total Submissions: 57694 My SubmissionsImplement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.
2014-09-04 20:23:30
405
原创 [LeetCode] String to Integer (atoi)
Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input ca
2014-09-03 17:44:41
436
原创 [LeetCode] 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)).
2014-09-02 21:11:03
404
原创 [LeetCode] Simplify Path
Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"public class Solution { public String simplifyPath
2014-08-28 15:23:07
334
原创 [LeetCode] Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".
2014-08-28 14:39:00
363
原创 [LeetCode] Maximal Rectangle
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.将二维的问题转换为一维问题
2014-08-27 17:16:30
385
原创 [LeetCode] Largest Rectangle in Histogram
Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.Above is a histogram where width o
2014-08-27 16:55:37
321
原创 [LeetCode] Decode Ways
A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total nu
2014-08-27 15:50:12
322
原创 [LeetCode] Restore IP Addresses
Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given "25525511135",return ["255.255.11.135", "255.255.111.35"]. (Order
2014-08-27 15:17:34
340
原创 [LeetCode] Minimum Window Substring
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S = "ADOBECODEBANC"T = "ABC"Minimum window is "BANC"
2014-08-27 14:33:41
368
原创 [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-08-27 10:54:02
376
原创 [LeetCode] Reverse Linked List II
Reverse a linked list from position m to n. Do it in-place and in one-pass.For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL.Note:Given m, n satisfy the
2014-08-27 00:06:41
342
原创 对象的序列化与Serializable 接口
对象的序列化与Serializable 接口1. 基本的序列化操作 一般来说,对象只存在与进程运行期间,进程中止后,你所创建的对象就灰飞烟灭。但是有的时候,你需要在程序中止后继续保留对象信息,这样下次运行时,你可以将对象重建恢复到程序上次运行时它所拥有的信息。 Java中提供了Serializable接口来标记可序列化的对象。public interface Ser
2014-08-24 19:52:27
515
原创 [LeetCode] Interleaving String
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 = "aadbbbaccc", r
2014-08-23 17:34:07
356
原创 [LeetCode] Validate Binary Search Tree
Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than the node's key.
2014-08-23 15:33:11
358
原创 [LeetCode] Recover Binary Search Tree
原题地址:https://oj.leetcode.com/problems/recover-binary-search-tree/Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:
2014-08-23 14:59:00
477
原创 [LeetCode] Construct Binary Tree from Inorder and Postorder Traversal
原题地址:https://oj.leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume
2014-08-22 20:57:16
435
原创 [LeetCode] Distinct Subsequences
Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleting some (can be non
2014-08-22 20:12:41
324
原创 [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-08-22 11:22:21
294
原创 [LeetCode] Longest Substring Without Repeating Characters
原题地址:https://oj.leetcode.com/problems/longest-substring-without-repeating-characters/Given a string, find the length of the longest substring without repeating characters. For example, the longe
2014-08-22 10:51:56
314
原创 [LeetCode] Longest Consecutive Sequence
原题链接: https://oj.leetcode.com/problems/longest-consecutive-sequence/Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given
2014-08-22 09:47:25
452
原创 [LeetCode] Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palindrome."race a car" is not a
2014-08-21 14:15:34
300
原创 [LeetCode] Surrounded Regions
Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'.A region is captured by flipping all 'O's into 'X's in that surrounded region.For example,X X X XX O O X
2014-08-21 12:57:35
330
原创 [LeetCode] Word Ladder
原题地址:https://oj.leetcode.com/problems/word-ladder/
2014-08-21 12:47:12
394
原创 [LeetCode] Palindrome Partitioning II
原题地址:https://oj.leetcode.com/problems/palindrome-partitioning-ii/Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palin
2014-08-21 10:02:58
553
原创 [LeetCode] Word Break II
题目链接:https://oj.leetcode.com/problems/word-break-ii/Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word.Return all
2014-08-21 09:51:57
631
原创 [LeetCode] Clone Graph
Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.OJ's undirected graph serialization:Nodes are labeled uniquely.We use # as a separator for ea
2014-08-20 21:27:32
435
原创 [面试题] 蚂蚁蚂蚁
题目:有一根长为Lcm的棍子,蚂蚁以1cm/s的速度在上面爬行,爬到两端就会从棍子上掉下,当两个蚂蚁相向爬行碰到即往相反方向爬行。知道所有蚂蚁离棍子左端的距离x[i],但蚂蚁的爬行方向随机,求所有蚂蚁掉落的最小时间和最大时间。
2014-08-20 15:49:23
718
原创 [面试题] 递增序列生成
思路:和《剑指OFFER》中求丑数的题目很像,序列中第N个数 必然是是前N - 1个数乘以 2 或者乘以5 中大于第N - 1个数的最小值。可以通过分别标记上次乘以2 或乘以5的位置开始寻找被乘数。取最小值,如果 乘以2 的小 则第N个数为该数,同时将2的标记位置右移一位,同理乘以5小时右移5的标记位置,二者相同时同时右移两位。显然,肯定能保证所得数比上一个数大。
2014-08-20 13:55:15
778
原创 [LeetCode] Gas Station
There are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to it
2014-08-19 20:39:11
451
原创 [LeetCode] Candy
There are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must have at least on
2014-08-19 20:08:39
279
原创 [LeetCode] Copy List with Random Pointer
A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list.
2014-08-19 16:14:54
302
原创 [LeetCode] LRU Cache
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set.get(key) - Get the value (will always be positive) of the key if
2014-08-18 20:27:43
332
原创 [LeetCode] Insertion Sort List
Insertion Sort List Total Accepted: 18506 Total Submissions: 73505 My SubmissionsSort a linked list using insertion sort.链表的插入排序,没什么
2014-08-18 15:25:18
297
原创 [LeetCode] Sort List
Sort a linked list in O(n log n) time using constant space complexity.public class SortList { static class ListNode { int val; ListNode next; ListNode(int x) { val =
2014-08-15 17:06:48
306
原创 [LeetCode] Max Points on a Line
Max Points on a Line Total Accepted: 16037 Total Submissions: 148156 My SubmissionsGiven n points on a 2D plane, find the maximum number of points that lie on the same straight line.
2014-08-15 14:56:34
310
原创 [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-08-14 19:42:28
288
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人