
编程题目
EnjoyCodingAndGame
Nothing raplaces hard work.
纸上得来终觉浅,绝知此事要躬行。
展开
-
LeetCode 14 - Roman to Integer
Roman to IntegerWrite a function to find the longest common prefix string amongst an array of strings.My Codeclass Solution {public: string longestCommonPrefix(vecto原创 2015-12-22 16:48:37 · 488 阅读 · 0 评论 -
LeetCode 58 - Length of Last Word
Length of Last WordGiven 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, r原创 2016-03-09 18:42:18 · 373 阅读 · 0 评论 -
LeetCode 57 - Insert Interval
Insert IntervalGiven 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 th原创 2016-03-09 18:22:15 · 367 阅读 · 0 评论 -
LeetCode 56 - Merge Intervals
Merge IntervalsGiven 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].My Code/** * Definition for原创 2016-03-08 13:17:48 · 335 阅读 · 0 评论 -
LeetCode 55 - Jump Game
Jump GameGiven 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.原创 2016-03-07 20:35:40 · 353 阅读 · 0 评论 -
LeetCode 54 - Spiral Matrix
Spiral MatrixGiven a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ],原创 2016-03-07 20:13:16 · 349 阅读 · 0 评论 -
LeetCode 51 - N-Queens II
N-Queens IIFollow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.My Codeclass Solution {public: bool inline原创 2016-03-05 13:55:36 · 382 阅读 · 0 评论 -
LeetCode 51 - N-Queens
N-QueensThe 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-q原创 2016-03-05 13:48:16 · 308 阅读 · 0 评论 -
LeetCode 50 - Pow(x, n)
Pow(x, n)Implement pow(x, n).My Binary Codeclass Solution {public: double myPow(double x, int n) { if (n == 0) return 1; if (n == -1) r原创 2016-03-05 12:15:38 · 361 阅读 · 0 评论 -
LeetCode 49 - Group Anagrams
Group AnagramsGiven an array of strings, group anagrams together.For example, given: ["eat", "tea", "tan", "ate", "nat", "bat"], Return:[ ["ate", "eat","tea"], ["nat","tan"], ["bat原创 2016-03-04 21:36:45 · 457 阅读 · 0 评论 -
LeetCode 48 - Rotate Image
Rotate ImageYou are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?My Codeclass Solution {public:原创 2016-03-04 19:45:01 · 260 阅读 · 0 评论 -
LeetCode 47 - Permutations II
Permutations IIGiven 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原创 2016-03-04 18:32:17 · 346 阅读 · 0 评论 -
LeetCode 46 - Permutations
PermutationsGiven a collection of distinct numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], an原创 2016-03-04 17:11:44 · 321 阅读 · 0 评论 -
LeetCode 31 - Next Permutation
Next PermutationImplement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it原创 2016-02-25 17:10:45 · 313 阅读 · 0 评论 -
LeetCode 32 - Longest Valid Parentheses
Longest Valid ParenthesesGiven a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the longest valid pa原创 2016-02-25 21:20:05 · 397 阅读 · 0 评论 -
LeetCode 33 - Search in Rotated Sorted Array
Search in Rotated Sorted ArraySuppose 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 7 0 1 2).You are given a target value to原创 2016-02-29 17:11:52 · 371 阅读 · 0 评论 -
LeetCode 34 - Search for a Range
Search for a RangeGiven a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If原创 2016-03-01 15:24:15 · 337 阅读 · 0 评论 -
LeetCode 35 - Search Insert Position
Search Insert PositionGiven 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 in order.You may assume原创 2016-03-01 15:51:21 · 349 阅读 · 0 评论 -
LeetCode 59 - Spiral Matrix II
Spiral Matrix IIGiven an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.For example,Given n = 3,You should return the following matrix:[ [ 1, 2,原创 2016-03-11 16:41:53 · 429 阅读 · 0 评论 -
LeetCode 60 - Permutation Sequence
Permutation SequenceThe 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):原创 2016-03-11 17:17:18 · 448 阅读 · 0 评论 -
LeetCode 61 - Rotate List
Rotate ListGiven 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.My Code/** *原创 2016-04-05 15:39:23 · 337 阅读 · 0 评论 -
Round B APAC Test 2017 Problem A. Sherlock and Parentheses
Problem A. Sherlock and ParenthesesSherlock and Watson have recently enrolled in a computer programming course. Today, the tutor taught them about the balanced parentheses problem. A string S cons原创 2016-10-07 21:51:11 · 613 阅读 · 0 评论 -
Round C APAC Test 2017 Problem D. Soldiers
Problem D. SoldiersGeneral Alice and General Bob are playing a war game. There are N soldiers in the game. Each soldier has two stats: attack and defense.Before the game starts, General Alice an原创 2016-10-07 00:17:26 · 934 阅读 · 0 评论 -
Round C APAC Test 2017 Problem C. Evaluation
Problem C. EvaluationGiven an unordered list of assignment statements, write a program to determine whether the assignment statements can be put in some order in which all variables can be evaluat原创 2016-10-05 15:59:53 · 797 阅读 · 0 评论 -
Round C APAC Test 2017 Problem B. Monster Path
Problem B. Safe SquaresCodejamon trainers are actively looking for monsters, but if you are not a trainer, these monsters could be really dangerous for you. You might want to find safe places that原创 2016-10-04 16:13:54 · 555 阅读 · 0 评论 -
Round C APAC Test 2017 Problem A. Monster Path
Problem A. Monster PathCodejamon is a mobile game in which monster trainers walk around in the real world to catch monsters. You have an old smartphone with a short battery life, so you need原创 2016-10-03 23:50:47 · 943 阅读 · 0 评论 -
LeetCode 69 - Sqrt(x)
Sqrt(x)Implement int sqrt(int x).Compute and return the square root of x.My Codeclass Solution {public: int mySqrt(int x) { if (x == 0) return 0; else原创 2016-10-17 21:46:04 · 392 阅读 · 0 评论 -
LeetCode 68 -Text Justification
Text JustificationGiven 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原创 2016-10-17 21:10:31 · 656 阅读 · 0 评论 -
LeetCode 67 - Add Binary
Add BinaryGiven two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".My Codeclass Solution {public: string addBinary(str原创 2016-10-17 19:51:32 · 379 阅读 · 0 评论 -
LeetCode 53 - Maximum Subarray
Maximum SubarrayFind 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 contiguou原创 2016-03-05 15:15:39 · 334 阅读 · 0 评论 -
LeetCode 66 - Plus One
Plus OneGiven 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.My原创 2016-10-17 18:49:06 · 599 阅读 · 0 评论 -
Round B APAC Test 2017 Problem D. Sherlock and Permutation Sorting
Problem D. Sherlock and Permutation SortingSherlock and Watson have already been introduced to sorting in their computer programming course. Now, Watson has always been curious about parallel comp原创 2016-10-09 14:15:42 · 750 阅读 · 0 评论 -
Round B APAC Test 2017 Problem C. Watson and Intervals
Problem C. Watson and IntervalsSherlock and Watson have mastered the intricacies of the language C++ in their programming course, so they have moved on to algorithmic problems. In today's class, t原创 2016-10-08 21:57:20 · 959 阅读 · 0 评论 -
Round B APAC Test 2017 Problem B. Sherlock and Watson Gym Secrets
Problem B. Sherlock and Watson Gym SecretsWatson and Sherlock are gym buddies.Their gym trainer has given them three numbers, A, B, and N, and has asked Watson and Sherlock to pick two differe原创 2016-10-08 16:36:14 · 1481 阅读 · 0 评论 -
LeetCode 65 - Valid Number
Valid NumberValidate 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 state原创 2016-04-07 18:42:51 · 488 阅读 · 0 评论 -
LeetCode 64 - Minimum Path Sum
Minimum Path SumGiven 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 e原创 2016-04-05 20:00:24 · 461 阅读 · 0 评论 -
LeetCode 63 - Unique Paths II
Unique Paths IIFollow 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 r原创 2016-04-05 17:11:03 · 412 阅读 · 0 评论 -
LeetCode 62 - Unique Paths
Unique PathsA 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 tr原创 2016-04-05 16:36:13 · 367 阅读 · 0 评论 -
LeetCode 36 - Valid Sudoku
Valid SudokuDetermine 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 '.'.原创 2016-03-01 16:41:45 · 378 阅读 · 0 评论 -
LeetCode 37 - Sudoku Solver
Sudoku SolverWrite 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原创 2016-03-01 21:37:09 · 455 阅读 · 0 评论