- 博客(79)
- 资源 (4)
- 收藏
- 关注
原创 221.Maximal Square
Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and return its area.For example, given the following matrix:1 0 1 0 01 0 1 1 11 1 1 1 11 0 0 1 0
2015-06-30 15:22:04 432
原创 209.Minimum Size Subarray Sum
Given an array of n positive integers and a positive integer s, find the minimal length of a subarray of which the sum ≥ s. If there isn't one, return 0 instead.For example, given the array [2,3
2015-06-30 11:47:56 584
原创 93.Restore IP Addresses
Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given "25525511135",return ["255.255.11.135", "255.255.111.35"]. (Order
2015-06-30 11:08:44 588
原创 208.Implement Trie (Prefix Tree)
Implement a trie with insert, search, and startsWith methods.Note:You may assume that all inputs are consist of lowercase letters a-z.class TrieNode {public: // Initialize your data s
2015-06-30 08:48:24 347
原创 213.House Robber II
Note: This is an extension of House Robber.After robbing those houses on that street, the thief has found himself a new place for his thievery so that he will not get too much attention. This time
2015-06-30 08:42:50 618
原创 198.House Robber
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent house
2015-06-30 08:40:20 439
原创 82. Remove Duplicates from Sorted List II
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given 1->2->3->3->4->4->5, return 1->2->5.Given 1->1-
2015-06-29 21:01:20 846
原创 83. Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3.注意while循环的判断/** * Defi
2015-06-29 20:18:53 411
原创 81. 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?Write a function to determine if a given target is in the
2015-06-29 15:57:40 394
原创 80.Remove Duplicates from Sorted Array II
Follow up for "Remove Duplicates":What if duplicates are allowed at most twice?For example,Given sorted array nums = [1,1,1,2,2,3],Your function should return length = 5, with the first fi
2015-06-29 15:37:26 578
原创 124.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-06-29 15:06:50 529
原创 99.Recover Binary Search Tree
Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is pretty straight forward. Could you devis
2015-06-29 14:31:23 347
原创 98.Validate Binary Search Tree&检查是否为BST
Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than the node's key.Th
2015-06-29 11:35:29 611
原创 Basic Calculator II
Implement a basic calculator to evaluate a simple expression string.The expression string contains only non-negative integers, +, -, *, / operators and empty spaces . The integer division should
2015-06-29 10:04:51 1089
原创 224.Basic Calculator
Implement a basic calculator to evaluate a simple expression string.The expression string may contain open ( and closing parentheses ), the plus + or minus sign -, non-negative integers and em
2015-06-29 09:45:54 546
原创 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
2015-06-27 14:21:05 472
原创 74.Search a 2D Matrix&240. Search a 2D Matrix II
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 left to right.The first integer of each
2015-06-27 13:58:20 535
原创 73.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.class Solution {public: void setZeroes(vector>& matrix) { set zeroRows; set zeroCo
2015-06-27 11:26:51 521
原创 225.Implement Stack using Queues
Implement the following operations of a stack using queues.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get the top element.empty() -- Return whet
2015-06-27 10:47:46 338
原创 71.Simplify Path
字符串处理,由于".."是返回上级目录(如果是根目录则不处理),因此可以考虑用栈记录路径名,以便于处理。需要注意几个细节:重复连续出现的'/',只按1个处理,即跳过重复连续出现的'/';如果路径名是".",则不处理;如果路径名是"..",则需要弹栈,如果栈为空,则不做处理;如果路径名为其他字符串,入栈。最后,再逐个取出栈中元素(即已保存的路径名),用'/'分隔并连接起来,不过要注意
2015-06-27 10:15:10 628
原创 228.Summary Ranges
Given a sorted integer array without duplicates, return the summary of its ranges.For example, given [0,1,2,4,5,7], return ["0->2","4->5","7"].注意int与string的转换,以及溢出的问题class Solution {p
2015-06-26 16:46:26 451
原创 69.Sqrt(x)
Implement int sqrt(int x).Compute and return the square root of x.class Solution {public: int mySqrt(int x) { int left = 1; int right = x >>1; int mid; int
2015-06-26 16:01:50 550
原创 70.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?class Solution {public:
2015-06-26 15:51:41 353
原创 67. Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".class Solution {public: string addBinary(string a, string b) {
2015-06-26 15:29:11 619
原创 66. Plus One
Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list.机智的解法class S
2015-06-26 15:16:24 424
原创 65.Valid Number&表示数值的字符串
Validate if a given string is numeric.Some examples:"0" => true" 0.1 " => true"abc" => false"1 a" => false"2e10" => trueNote: It is intended for the problem statement to be ambiguo
2015-06-26 11:37:14 1724
原创 64. 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
2015-06-26 09:47:22 382
原创 63.Unique Paths II&机器人走方格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
2015-06-26 09:21:59 500
原创 62. Unique Paths&机器人走方格I
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
2015-06-26 09:17:51 661
原创 Rotate List
Given a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL.1/** * Definition fo
2015-06-26 09:15:49 321
原创 223. Rectangle Area
Find the total area covered by two rectilinear rectangles in a 2D plane.Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.Assume that the tota
2015-06-26 09:05:42 347
原创 Invert Binary Tree
Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1Solution1,递归/** * Definition for a binary tree node. * struct Tre
2015-06-25 21:21:40 379
原创 58. 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
2015-06-25 11:21:13 425
原创 Insert Interval
Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their start times.E
2015-06-25 10:59:30 354
原创 Merge Intervals
Given a collection of intervals, merge all overlapping intervals.For example,Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,18]./** * Definition for an interval. * struct Inter
2015-06-25 10:15:15 318
原创 55. 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 if y
2015-06-25 09:44:58 347
原创 53.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] has
2015-06-25 09:04:37 1365
原创 N-Queens II
Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.Hide Tags Backtrackingdddclass So
2015-06-24 17:06:40 331
原创 51.N-Queens&n皇后问题
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.Eac
2015-06-24 16:59:45 466
原创 43. Multiply Strings
Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-negative.当年的百位大数没有好好写啊。。。。。就知道抄抄抄
2015-06-09 15:17:00 681
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人