- 博客(35)
- 资源 (16)
- 收藏
- 关注
原创 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 ambiguous.
2015-06-30 11:17:58 408
原创 Majority Element II
Given an integer array of size n, find all elements that appear more than⌊ n/3 ⌋ times. The algorithm should run in linear time and in O(1) space.class Solution {public: vector majorityElemen
2015-06-30 00:30:33 2255
原创 Regular Expression Matching
Implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the entire input
2015-06-29 03:19:31 338
原创 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
2015-06-28 02:44:52 318
原创 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"].class Solution {public: vector summaryRanges
2015-06-27 00:33:59 1460
原创 Text Justification
Given an array of words and a length L, format the text such that each line has exactlyL characters and is fully (left and right) justified.You should pack your words in a greedy approach; that is
2015-06-26 00:51:07 484
原创 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 puzzle.
2015-06-24 23:44:16 303
原创 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-23 02:00:47 898
原创 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-22 16:06:19 2437 3
原创 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 "()",
2015-06-22 02:02:59 362
原创 Number of Islands
Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assu
2015-06-22 00:20:22 377
原创 Contains Duplicate III
Given an array of integers, find out whether there are two distinct indices i and j in the array such that the difference between nums[i] and nums[j] is at most t and the difference between i an
2015-06-21 03:23:38 940
原创 N-Queens II
Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.class Solution {public: void visit(int n, unsigned int left,
2015-06-20 01:35:49 617
原创 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.Eac
2015-06-20 01:16:54 325
原创 String to Integer (atoi)
Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input case
2015-06-18 00:05:09 324
原创 Scramble String
Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation of s1 = "great": great / \ gr
2015-06-17 21:57:40 558
原创 Maximal Rectangle
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.class Solution {public: int visit(vector &height) { height.push_
2015-06-16 02:53:16 319
原创 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
2015-06-13 00:17:27 349
原创 3Sum Closest
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 three integers. You may assume that each input would have exactly
2015-06-12 02:07:28 345
原创 4Sum
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note: Elements in
2015-06-12 00:53:28 329
原创 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-11 23:41:41 1295 3
原创 Permutations II
Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2] have the following unique permutations:[1,1,2], [1,2,1], and [2,1,1].
2015-06-11 20:07:15 324
原创 Count Complete Tree Nodes
Given a complete binary tree, count the number of nodes.Definition of a complete binary tree from Wikipedia:In a complete binary tree every level, except possibly the last, is completely filled,
2015-06-10 23:19:49 1896
原创 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 empty
2015-06-10 02:12:12 1300
原创 Largest Rectangle in Histogram
Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.Above is a histogram where width of ea
2015-06-09 01:54:57 334
原创 Rectangle Area
Find the total area covered by two rectilinear rectangles in a2D plane.Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.Assume that the total a
2015-06-08 02:07:13 1820
原创 Best Time to Buy and Sell Stock IV
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 k transactions.Note:You may no
2015-06-07 02:02:59 636
原创 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-06-06 23:32:03 332
原创 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-06 02:03:10 1469
原创 Reverse Nodes in k-Group
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is.
2015-06-04 19:33:57 319
原创 Interleaving String
Given s1, s2, s3, find whether s3 is formed by the interleaving ofs1 and s2.For example,Given:s1 = "aabcc",s2 = "dbbca",When s3 = "aadbbcbcac", return true.When s3 = "aadbbbaccc", return
2015-06-04 00:03:00 317
原创 Gas Station
There are N gas stations along a circular route, where the amount of gas at stationi is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from stationi to it
2015-06-03 01:35:18 416
原创 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]
2015-06-02 02:20:21 311
原创 Longest Palindromic Substring
Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.class Solution {p
2015-06-01 12:57:25 346
原创 Copy List with Random Pointer
There is a list which contains random pointer in each node.Please do the deep copy for this list.struct RandomListNode{ int label; RandomListNode *next, *random; RandomListNode(int x) : label(
2015-06-01 00:51:46 311
exceptional c++ style中文版 pdf 刘未鹏译
2010-09-26
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人