Math Game
文章平均质量分 61
所难
这个作者很懒,什么都没留下…
展开
-
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原创 2014-08-03 17:26:12 · 273 阅读 · 0 评论 -
LeetCode-Permutation Sequence
The set [1,2,3,…,n] contains a total of n! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence (ie, for n = 3):"123""132""213""231""3原创 2014-08-13 20:04:33 · 293 阅读 · 0 评论 -
LeetCode-Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A word is原创 2014-08-13 20:39:30 · 301 阅读 · 0 评论 -
LeetCode-Unique Paths II
Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as 1 and 0 respectively in the原创 2014-08-11 23:08:09 · 230 阅读 · 0 评论 -
LeetCode-Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right at原创 2014-08-11 22:48:20 · 253 阅读 · 0 评论 -
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-07-30 10:11:10 · 367 阅读 · 0 评论 -
LeetCode-Text Justification
Given an array of words and a length L, format the text such that each line has exactly L characters and is fully (left and right) justified.You should pack your words in a greedy approach; that i原创 2014-08-11 21:17:14 · 300 阅读 · 0 评论 -
LeetCode-Unique Paths
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the原创 2014-08-11 23:24:31 · 223 阅读 · 0 评论 -
LeetCode-Set Matrix Zeroes
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.click to show follow up.Follow up:Did you use extra space?A straight forward solution using O(m原创 2014-08-10 16:05:38 · 399 阅读 · 0 评论 -
LeetCode-Simplify Path
Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"click to show corner cases.Corner Cases:Did原创 2014-08-10 21:11:06 · 279 阅读 · 0 评论 -
LeetCode-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 the top?Solution:C原创 2014-08-11 09:14:02 · 171 阅读 · 0 评论 -
LeetCode-Count and Say
The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11.11 is read off as "two 1s" or 21.21 is read off as原创 2014-08-16 13:28:03 · 289 阅读 · 0 评论 -
LeetCode-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 at that position.Determine i原创 2014-08-13 22:00:04 · 232 阅读 · 0 评论 -
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-07-30 09:46:38 · 280 阅读 · 0 评论 -
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 / \原创 2014-08-03 17:14:18 · 302 阅读 · 0 评论 -
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]]原创 2014-08-02 13:29:33 · 218 阅读 · 0 评论 -
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?Solution:原创 2014-08-02 09:50:15 · 211 阅读 · 0 评论 -
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], [原创 2014-08-01 15:00:41 · 243 阅读 · 0 评论 -
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 may原创 2014-08-01 11:14:17 · 346 阅读 · 0 评论 -
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原创 2014-08-01 11:41:49 · 143 阅读 · 0 评论 -
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原创 2014-07-31 11:13:17 · 235 阅读 · 0 评论 -
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),原创 2014-08-01 13:37:35 · 209 阅读 · 0 评论 -
LeetCode-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],the contiguous subarray [4,−1,2,1] ha原创 2014-08-13 22:50:56 · 275 阅读 · 0 评论 -
LeetCode-N-Queens II
Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.Solution:Code:class Solution {public: void helper(in原创 2014-08-14 16:29:20 · 339 阅读 · 0 评论 -
LeetCode-Sort Colors
Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the integers原创 2014-08-10 10:15:28 · 378 阅读 · 0 评论 -
LeetCode-First Missing Positive
Given an unsorted integer array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm should run in O(n) time and uses constant原创 2014-08-15 21:52:56 · 331 阅读 · 0 评论 -
LeetCode-Valid Parentheses
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all va原创 2014-08-18 11:23:22 · 266 阅读 · 0 评论 -
LeetCode-Generate Parentheses
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:"((()))", "(()())", "(())()", "()(())", "()()原创 2014-08-18 11:13:33 · 252 阅读 · 0 评论 -
LeetCode-Divide Two Integers
Divide two integers without using multiplication, division and mod operator.Solution:Code:原创 2014-08-17 17:29:40 · 346 阅读 · 0 评论 -
LeetCode-Valid Sudoku
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character '.'.A partially fille原创 2014-08-16 16:07:51 · 253 阅读 · 0 评论 -
LeetCode-Next Permutation
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible原创 2014-08-17 14:48:00 · 299 阅读 · 0 评论 -
LeetCode-Sudoku Solver
Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character '.'.You may assume that there will be only one unique solution.A sudoku原创 2014-08-16 15:55:55 · 321 阅读 · 0 评论 -
LeetCode-Longest Valid Parentheses
Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the longest valid parentheses substring is "()",原创 2014-08-17 14:31:18 · 274 阅读 · 0 评论 -
LeetCode-Wildcard Matching
Implement wildcard pattern matching with support for '?' and '*'.'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequence).The matching should cover t原创 2014-08-15 13:35:10 · 257 阅读 · 0 评论 -
LeetCode-Jump Game II
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 at that position.Your goal i原创 2014-08-15 13:06:53 · 310 阅读 · 0 评论 -
LeetCode-N-Queens
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens puzzle.原创 2014-08-14 16:28:36 · 265 阅读 · 0 评论 -
LeetCode-Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.click to show spoilers.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of convertin原创 2014-08-18 21:18:37 · 327 阅读 · 0 评论 -
LeetCode-Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321click to show spoilers.Have you thought about this?Here are some good questions to ask before c原创 2014-08-18 21:44:03 · 291 阅读 · 0 评论 -
LeetCode-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 endpoints of line i is at (i, ai) and (i, 0). Fin原创 2014-08-18 14:53:53 · 339 阅读 · 0 评论 -
LeetCode-Trapping Rain Water
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example, Given [0,1,0,2,1,0,1,3,2,1,2,1]原创 2014-08-15 21:33:28 · 212 阅读 · 0 评论