5*
文章平均质量分 78
xiaoo_gan
做一个快乐的程序员
展开
-
[LeetCode 85] Maximal Rectangle (华为2015机试)
题目链接:maximal-rectangleimport java.util.Arrays;/** * Given a 2D binary matrix filled with 0's and 1's, * find the largest rectangle containing all ones and return its area. * */public cl原创 2015-04-12 11:37:19 · 915 阅读 · 0 评论 -
[LeetCode 98] Validate Binary Search Tree
题目链接: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 subtr原创 2015-03-23 10:27:07 · 1025 阅读 · 0 评论 -
[LeetCode 51&52] N-Queens I & II (N皇后问题)
题目链接:n-queensimport java.util.ArrayList;import java.util.Arrays;import java.util.List;/** * The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no t原创 2015-03-30 23:31:19 · 1008 阅读 · 0 评论 -
[LeetCode 101] Symmetric Tree
题目链接:symmetric-treeimport java.util.LinkedList;//判断该二叉树是否是对称二叉树/** * Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this原创 2015-03-22 10:39:58 · 792 阅读 · 0 评论 -
[LeetCode 190] Reverse Bits
题目链接:reverse-bitsimport java.util.Arrays;/** * Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in binary as 0000001010010100000111101原创 2015-03-22 14:20:14 · 3980 阅读 · 0 评论 -
[LeetCode 55] Jump Game
题目链接:jump-game/** * Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length原创 2015-03-29 13:02:42 · 1319 阅读 · 0 评论 -
[LeetCode 74] Search a 2D Matrix
题目链接:search-a-2d-matrix/** * Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted from le原创 2015-03-21 12:18:54 · 789 阅读 · 0 评论 -
[LeetCode 39&40] Combination Sum I & II
题目链接:combination-sumimport java.util.ArrayList;import java.util.Arrays;import java.util.List;/** * Given a set of candidate numbers (C) and a target number (T), find all unique combin原创 2015-03-28 23:41:07 · 1108 阅读 · 0 评论 -
[LeetCode 172] Factorial Trailing Zeroes
题目链接:factorial-trailing-zeroes/** * Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in logarithmic time complexity. * */public class原创 2015-03-21 10:03:03 · 631 阅读 · 0 评论 -
[LeetCode 28] Implement strStr()
题目链接:implement-strstr/** * Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. * */public class Implement原创 2015-03-21 15:38:28 · 431 阅读 · 0 评论 -
[LeetCode 142] Linked List Cycle II
题目链接: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?原创 2015-03-31 15:31:04 · 585 阅读 · 0 评论 -
123.Best Time to Buy and Sell Stock III
题目链接:best-time-to-buy-and-sell-stock-iiiimport java.util.Arrays;/** * * Say you have an array for which the ith element is the price of a given stock on day i. * Design an algorithm to fi原创 2015-03-18 10:34:46 · 395 阅读 · 0 评论 -
[LeetCode 36&37] Valid Sudoku & Sudoku Solver (数独问题)
题目链接:valid-sudokuimport java.util.Arrays;/** * Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be partially filled, where empty cells原创 2015-03-31 11:09:09 · 783 阅读 · 0 评论 -
[LeetCode 17] Letter Combinations of a Phone Number
题目链接:letter-combinations-of-a-phone-numberimport java.util.ArrayList;import java.util.Arrays;import java.util.List;/** * Given a digit string, return all possible letter combinations tha原创 2015-03-24 12:13:03 · 848 阅读 · 0 评论 -
[LeetCode 43] Multiply Strings
题目链接:multiply-stringsimport java.util.Arrays;/** * Given two numbers represented as strings, return multiplication of the numbers as a string. Note: The numbers can be arbitrarily lar原创 2015-03-24 09:13:40 · 763 阅读 · 0 评论 -
[LeetCode 135] Candy
题目链接:candyimport java.util.Arrays;/** * 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 follo原创 2015-04-02 22:46:50 · 472 阅读 · 0 评论 -
[LeetCode 50] Pow(x, n)
题目链接:powx-n/** * Implement pow(x, n). * */public class PowXN {// 299 / 299 test cases passed.// Status: Accepted// Runtime: 343 ms// Submitted: 0 minutes ago static double po原创 2015-03-24 12:16:16 · 1217 阅读 · 0 评论 -
[LeetCode 79] Word Search
题目链接:word-search/** * Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells原创 2015-04-03 00:57:53 · 857 阅读 · 0 评论 -
171.Excel Sheet Column Number
题目链接:excel-sheet-column-number/** * Related to question Excel Sheet Column Title * Given a column title as appear in an Excel sheet, return its corresponding column number. * For example:原创 2015-03-18 22:44:32 · 560 阅读 · 0 评论 -
27.Remove Element
题目链接:remove-element/** * * Given an array and a value, remove all instances of that value in place and return the new length. * * The order of elements can be changed. It doesn't matter wha原创 2015-03-18 17:35:12 · 438 阅读 · 0 评论 -
16.3Sum Closest
题目链接:3sum-closestimport java.util.Arrays;/** * * Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. * Return the sum of the原创 2015-03-18 16:48:59 · 439 阅读 · 0 评论 -
116.Populating Next Right Pointers in Each Node
题目链接:populating-next-right-pointers-in-each-node/** * Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }原创 2015-03-18 23:47:33 · 1043 阅读 · 0 评论 -
141.Linked List Cycle
题目链接:linked-list-cycle/** * * Given a linked list, determine if it has a cycle in it. * Follow up: * Can you solve it without using extra space? * */public class LinkedListCycle { pu原创 2015-03-18 23:12:09 · 537 阅读 · 0 评论 -
5.Longest Palindromic Substring
题目链接:longest-substring-without-repeating-characters/** * * Given a string S, find the longest palindromic substring in S. * You may assume that the maximum length of S is 1000, * and ther原创 2015-03-16 12:42:21 · 432 阅读 · 0 评论 -
81.Search in Rotated Sorted Array II
题目链接:search-in-rotated-sorted-array-ii/** * * Follow up for "Search in Rotated Sorted Array": * What if duplicates are allowed? * * Would this affect the run-time complexity? How and why?原创 2015-03-17 11:23:19 · 814 阅读 · 0 评论 -
153.Find Minimum in Rotated Sorted Array [LeetCode Java实现]
题目链接:find-minimum-in-rotated-sorted-array有待继续优化代码结构,但是已经AC了/** * Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6原创 2015-03-19 19:03:14 · 1346 阅读 · 0 评论 -
108. Convert Sorted Array to Binary Search Tree
题目链接:convert-sorted-array-to-binary-search-tree/** * Given an array where elements are sorted in ascending order, convert it to a height balanced BST. * */public class ConvertSortedArray原创 2015-03-19 17:50:24 · 505 阅读 · 0 评论 -
70.Climbing Stairs
题目链接:climbing-stairs/** * You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to th原创 2015-03-19 17:12:58 · 496 阅读 · 0 评论 -
144.Binary Tree Preorder Traversal
题目链接:binary-tree-preorder-traversalimport java.util.ArrayList;import java.util.List;import java.util.Stack;/** * Given a binary tree, return the preorder traversal of its nodes' values.原创 2015-03-19 00:34:09 · 585 阅读 · 0 评论 -
96.Unique Binary Search Trees [LeetCode Java实现]
题目链接:unique-binary-search-treesimport java.util.Arrays;/** * Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For example, Given n = 3, th原创 2015-03-19 16:26:55 · 777 阅读 · 0 评论 -
53.Maximum Subarray
题目链接: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], t原创 2015-03-19 10:59:20 · 476 阅读 · 0 评论 -
35.Search Insert Position
题目链接:search-insert-position有待继续优化/** * * Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted原创 2015-03-19 13:08:41 · 415 阅读 · 0 评论 -
[LeetCode 109] Convert Sorted List to Binary Search Tree
题目链接: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. * */public class Conve原创 2015-03-25 22:51:35 · 731 阅读 · 0 评论 -
145.Binary Tree Postorder Traversal
题目链接:binary-tree-postorder-traversalimport java.util.ArrayList;import java.util.List;import java.util.Stack;/** * Given a binary tree, return the postorder traversal of its nodes' valu原创 2015-03-19 10:24:33 · 504 阅读 · 0 评论 -
169 Majority Element [LeetCode Java实现]
题目链接:majority-element/** * Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. You may assume that the arra原创 2015-03-19 14:17:34 · 701 阅读 · 0 评论 -
[LeetCode 117] Populating Next Right Pointers in Each Node II
题目链接:populating-next-right-pointers-in-each-node-ii相同题型:Populating Next Right Pointers in Each Nodeimport java.util.LinkedList;/** * Follow up for problem "Populating Next Right Poin原创 2015-03-26 09:57:24 · 625 阅读 · 0 评论 -
[LeetCode 148] Sort List
题目链接:sort-list/** * Sort a linked list in O(n log n) time using constant space complexity. * */public class SortList { public class ListNode { int val; ListNode next; ListNode(in原创 2015-03-26 08:29:22 · 655 阅读 · 0 评论 -
[LeetCode 114] Flatten Binary Tree to Linked List
题目链接:flatten-binary-tree-to-linked-listimport java.util.Stack;/** * Given a binary tree, flatten it to a linked list in-place. For example, Given 1 / \原创 2015-03-26 16:43:03 · 441 阅读 · 0 评论 -
[LeetCode 22] Generate Parentheses
题目链接:generate-parenthesesimport java.util.ArrayList;import java.util.List;/** * Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.原创 2015-03-28 00:31:08 · 859 阅读 · 0 评论 -
[LeetCode 11] Container With Most Water
题目链接:container-with-most-water/** * Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoi原创 2015-03-27 21:16:48 · 557 阅读 · 0 评论