- 博客(16)
- 收藏
- 关注
原创 ddd
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 following condi
2014-01-27 14:46:26 166
原创 Binary Tree Zigzag Level Order Traversal (LeetCode)
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).For example:Given binary
2014-01-27 13:10:35 435
原创 Convert Sorted List to Binary Search Tree (LeetCode)
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.用start和end两个point来记录当前的sublist,每次取中间值create new TreeNode后,用递归分别创建left subtree和right subtr
2014-01-27 12:57:39 572
原创 Path Sum II (LeetCode)
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 / \
2014-01-27 11:58:16 449
原创 Flatten Binary Tree to Linked List (LeetCode)
Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like: 1
2014-01-27 11:43:49 386
原创 Populating Next Right Pointers in Each Node II (LeetCode)
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 use constant
2014-01-27 11:16:34 416
原创 Distinct Subsequences (LeetCode)
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-01-27 10:01:27 398
原创 Edit Distance (LeetCode)
Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:
2014-01-27 09:08:58 403
原创 Binary Tree Maximum Path Sum (LeetCode)
Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree, 1 / \ 2 3Return 6
2014-01-26 12:50:37 534
原创 Word Ladder (LeetCode)
Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that:Only one letter can be changed at a timeEach intermediate word m
2014-01-26 12:23:50 452
原创 Longest Consecutive Sequence (LeetCode)
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-01-26 12:07:36 400
原创 Palindrome Partitioning (LeetCode)
Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s = "aab",Return [ ["aa","b"],
2014-01-26 11:51:11 424
原创 Reorder List (LeetCode)
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
2014-01-26 07:39:57 364
原创 Sort List (LeetCode)
Sort a linked list in O(n log n) time using constant space complexity.看到 O(nlogn)第一想到的是merge sort,这里采用的是每次merge前遍历当前list,找到中间节点,然后对head和中间节点分别再进行sort,再merge。或者也可以用两个point,start和end,当start==end
2014-01-26 07:12:54 463
原创 Evaluate Reverse Polish Notation (LeetCode)
用了stack,遍历数组,遇到数字就push,遇到运算符,取出stack中最近入栈的两个数进行计算,然后继续入栈。最后return stack中的结果即可public int evalRPN(String[] tokens) { if(tokens.length==0) return 0; Stack stack = new
2014-01-26 07:09:05 436
原创 Insertion Sort List (LeetCode)
public ListNode insertionSortList(ListNode head) { // IMPORTANT: Please reset any member data you declared, as // the same Solution instance will be reused for each test case.
2014-01-26 07:04:05 456
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人