![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
文章平均质量分 70
蜜莉恩
这个作者很懒,什么都没留下…
展开
-
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 阅读 · 0 评论 -
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 · 570 阅读 · 0 评论 -
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 阅读 · 0 评论 -
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 · 397 阅读 · 0 评论 -
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 · 401 阅读 · 0 评论 -
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 · 448 阅读 · 0 评论 -
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 · 414 阅读 · 0 评论 -
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 · 423 阅读 · 0 评论 -
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 · 398 阅读 · 0 评论 -
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 · 532 阅读 · 0 评论 -
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 · 450 阅读 · 0 评论 -
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 · 454 阅读 · 0 评论 -
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 · 363 阅读 · 0 评论 -
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 · 435 阅读 · 0 评论 -
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 · 432 阅读 · 0 评论