LeetCode
yukigenius
码农的工作,不码农的生活。
展开
-
杂谈!!
一不小心就开了一个博客,在一不小心居然FD不是现在写的这篇。 原本打算把这个原创 2014-08-18 10:39:06 · 217 阅读 · 0 评论 -
143【LeetCode】Reorder List
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-08-27 10:59:26 · 131 阅读 · 0 评论 -
144【LeetCode】Binary Tree Preorder Traversal
Binary Tree Preorder Traversal原创 2014-08-27 05:14:57 · 139 阅读 · 0 评论 -
136【LeetCode】Single Number
Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using e原创 2014-09-14 03:02:36 · 138 阅读 · 0 评论 -
134【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原创 2014-10-22 05:18:26 · 123 阅读 · 0 评论 -
137【LeetCode】Single Number II
Given an array of integers, every element appears three times except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without u原创 2014-09-14 11:31:29 · 128 阅读 · 0 评论 -
139【LeetCode】Word Break
{CSDN:CODE:465568}原创 2014-09-08 12:58:40 · 206 阅读 · 0 评论 -
141【LeetCode】Linked List Cycle
{CSDN:CODE:464939}原创 2014-09-06 11:23:57 · 171 阅读 · 0 评论 -
146【LeetCode】 LRU Cache
import java.util.HashMap;public class LRUCache {private int capacity;private CacheNodeList list;private HashMapmap; public LRUCache(int capacity) { this.capacity =原创 2014-08-26 11:41:34 · 207 阅读 · 0 评论 -
148【LeetCode】Sort List
Sort a linked list in O(n log n) time using constant space complexity.刚原创 2014-08-23 01:29:42 · 191 阅读 · 0 评论 -
151【LeetCode】Reverse Words in a String
public class Solution { public String reverseWords(String s) { String [] sub = s.split(" "); if(sub.length != 0){ String result = sub[sub.length-1]; fo原创 2014-08-18 02:39:59 · 163 阅读 · 0 评论 -
140【LeetCode】Word Break2
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 such possible sentences.For example, givens = "原创 2014-09-10 11:33:21 · 285 阅读 · 0 评论 -
142【LeetCode】Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Follow up:Can you solve it without using extra space?原创 2014-09-06 11:13:31 · 157 阅读 · 0 评论 -
147【LeetCode】Insertion Sort List
Sort a linked list using insertion sort.原创 2014-08-23 10:13:53 · 270 阅读 · 0 评论 -
131【LeetCode】Palindrome Partitioning
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","原创 2015-03-25 11:45:29 · 110 阅读 · 0 评论 -
132【LeetCode】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 palindrome partitioning of s.For example, given s = "aab",Return原创 2015-03-25 11:57:53 · 118 阅读 · 0 评论 -
135【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-10-22 05:15:35 · 131 阅读 · 0 评论 -
145【LeetCode】Binary Tree Postorder Traversal
Given a binary tree, return the postorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [3,2,1].Note: Recursive solut原创 2014-08-26 23:50:59 · 135 阅读 · 0 评论 -
133【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原创 2015-03-25 11:49:02 · 106 阅读 · 0 评论 -
128【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原创 2015-03-26 02:50:35 · 126 阅读 · 0 评论 -
127【LeetCode】Word Ladder
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原创 2015-03-26 03:15:03 · 117 阅读 · 0 评论 -
130【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原创 2015-03-26 01:35:06 · 169 阅读 · 0 评论 -
129【LeetCode】Sum Root to Leaf Numbers
Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number 123.Find the tota原创 2015-03-26 02:11:34 · 104 阅读 · 0 评论 -
125【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原创 2015-03-26 09:24:35 · 96 阅读 · 0 评论 -
121【LeetCode】Best Time to Buy and Sell Stock
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),原创 2015-03-26 11:40:27 · 113 阅读 · 0 评论 -
126【LeetCode】Word Ladder II
Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from start to end, such that:Only one letter can be changed at a timeEach intermediate word must exi原创 2015-03-26 03:25:29 · 183 阅读 · 0 评论 -
124【LeetCode】Binary Tree Maximum Path Sum
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.原创 2015-03-26 09:53:30 · 113 阅读 · 0 评论 -
123【LeetCode】Best Time to Buy and Sell Stock III
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most two transactions.Note:You ma原创 2015-03-26 11:18:20 · 113 阅读 · 0 评论 -
122【LeetCode】Best Time to Buy and Sell Stock II
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy on原创 2015-03-26 11:29:34 · 107 阅读 · 0 评论 -
119【LeetCode】Pascal's Triangle II
Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].Note:Could you optimize your algorithm to use only O(k) extra space?{CSDN:原创 2015-03-27 04:03:39 · 96 阅读 · 0 评论 -
118【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]]{CSDN:CODE:629006}原创 2015-03-27 04:06:03 · 139 阅读 · 0 评论 -
120【LeetCode】Triangle
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4], [原创 2015-03-26 21:18:35 · 107 阅读 · 0 评论 -
116【LeetCode】Populating Next Right Pointers in Each Node
Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right no原创 2015-03-28 09:18:28 · 99 阅读 · 0 评论 -
115【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原创 2015-03-28 10:29:36 · 112 阅读 · 0 评论 -
114【LeetCode】Flatten Binary Tree to Linked List
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原创 2015-03-28 10:31:56 · 129 阅读 · 0 评论 -
117【LeetCode】Populating Next Right Pointers in Each Node II
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原创 2015-03-28 09:32:00 · 108 阅读 · 0 评论 -
109【LeetCode】Convert Sorted List to Binary Search Tree
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.原创 2015-03-29 01:58:36 · 457 阅读 · 0 评论 -
111【LeetCode】Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.{CSDN:CODE:630431}原创 2015-03-29 00:36:39 · 105 阅读 · 0 评论 -
108【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.原创 2015-03-29 02:01:48 · 149 阅读 · 0 评论 -
112【LeetCode】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 binary tree and sum原创 2015-03-29 00:30:19 · 112 阅读 · 0 评论