Java
yukigenius
码农的工作,不码农的生活。
展开
-
149【LeetCode】Max Points on a Line
public class Solution { public int maxPoints(Point[] points) { if(points.length return points.length; } int max = 0; for(int i = 0; i f原创 2014-08-18 12:43:06 · 253 阅读 · 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 评论 -
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 评论 -
147【LeetCode】Insertion Sort List
Sort a linked list using insertion sort.原创 2014-08-23 10:13:53 · 270 阅读 · 0 评论 -
141【LeetCode】Linked List Cycle
{CSDN:CODE:464939}原创 2014-09-06 11:23:57 · 171 阅读 · 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 评论 -
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 评论 -
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 评论 -
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 评论 -
150【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-18 05:08:12 · 181 阅读 · 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 评论 -
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 评论 -
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 评论 -
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 评论 -
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 评论 -
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 评论 -
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 评论 -
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 评论 -
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 评论 -
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 评论 -
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 评论 -
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 评论 -
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 评论 -
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 评论 -
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 评论 -
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 评论 -
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 评论 -
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 评论 -
113【LeetCode】Path Sum II
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 / \原创 2015-03-29 00:26:54 · 102 阅读 · 0 评论 -
110【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原创 2015-03-29 01:21:51 · 114 阅读 · 0 评论 -
107【LeetCode】Binary Tree Level Order Traversal II
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree {3,9,20,#,#,15,7},原创 2015-03-29 05:25:56 · 113 阅读 · 0 评论 -
106【LeetCode】Construct Binary Tree from Inorder and Postorder Traversal
Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.{CSDN:CODE:630452}原创 2015-03-29 05:31:44 · 145 阅读 · 0 评论 -
103【LeetCode】Binary Tree Zigzag Level Order Traversal
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 tr原创 2015-03-29 09:07:10 · 193 阅读 · 0 评论