
LeetCode
MachineChen
这个作者很懒,什么都没留下…
展开
-
1.TwoSum
Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use the same ele原创 2017-05-13 15:21:54 · 390 阅读 · 0 评论 -
35. 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 in order.You may assume no duplicates in the array.Here原创 2017-10-19 21:53:21 · 205 阅读 · 0 评论 -
30. Substring with Concatenation of All Words
You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in words exactly once and wit原创 2017-10-12 01:18:15 · 356 阅读 · 0 评论 -
31. 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 orde原创 2017-10-13 00:08:05 · 448 阅读 · 0 评论 -
36.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 ‘.’.判断一个数独板是否是有效的,数独板存在空白格,用’.’表示。#i原创 2017-10-22 21:11:44 · 430 阅读 · 0 评论 -
37. 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. #include "SudokuSolver.h"b原创 2017-10-23 23:30:45 · 315 阅读 · 0 评论 -
38. Count and Say
The count-and-say sequence is the sequence of integers with the first five terms as following:1112112111112211 is read off as “one 1” or 11. 11 is read off as “two 1s” or 21. 21 is read off as原创 2017-10-24 21:04:39 · 209 阅读 · 0 评论 -
40. Combination Sum II
Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only be used once in the combination.No原创 2017-11-11 18:05:29 · 174 阅读 · 0 评论 -
41. 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 space. 给原创 2017-11-11 21:49:03 · 181 阅读 · 0 评论 -
32. 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 “()”, which has原创 2017-10-15 23:25:44 · 319 阅读 · 0 评论 -
42. 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], retu原创 2017-11-11 22:05:28 · 180 阅读 · 0 评论 -
43. Multiply Strings
Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2.Note:The length of both num1 and num2 is < 110.Both num1 and num2 contains only digits 0-9.Bo原创 2017-11-12 13:54:53 · 193 阅读 · 0 评论 -
39. Combination Sum
Given a set of candidate numbers (C) (without duplicates) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen from C原创 2017-10-25 22:07:57 · 202 阅读 · 0 评论 -
29. Divide Two Integers
Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT. 不使用乘法、除法和取余操作实现两数相除。 若数值溢出,返回MAX_INT.#include "limits.h"#include <algorithm>int DivideTw原创 2017-10-11 00:11:51 · 314 阅读 · 0 评论 -
34. Search for a Range
Given an array of integers sorted in ascending order, 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 the target is原创 2017-10-18 22:42:32 · 212 阅读 · 0 评论 -
33. Search in Rotated Sorted Array
Suppose an array sorted in ascending order 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 search. If found in the ar原创 2017-10-18 21:15:45 · 222 阅读 · 0 评论 -
2.AddTwoNumbers
You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it原创 2017-05-13 21:50:55 · 412 阅读 · 0 评论 -
3.LongestSubstringWithoutRepeatingCharacters
Given a string, find the length of the longest substring without repeating characters.Examples:Given “abcabcbb”, the answer is “abc”, which the length is 3.Given “bbbbb”, the answer is “b”, with the le原创 2017-05-13 22:52:20 · 283 阅读 · 0 评论 -
4.MedianOfTwoSortedArrays
There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).Example 1:nums1 = [1, 3] nums2原创 2017-05-17 23:45:43 · 404 阅读 · 0 评论 -
5.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.Example:Input: “babad”Output: “bab”Note: “aba” is also a valid answer.给定一个字符串,找出它的最长回文原创 2017-08-07 23:34:24 · 289 阅读 · 0 评论 -
6. ZigZag Conversion
The string “PAYPALISHIRING” is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H N A P L S I I G原创 2017-08-08 00:40:19 · 260 阅读 · 0 评论 -
22. 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: [ "((()))", "(()())", "(())()", "()(())", "原创 2017-09-26 21:26:11 · 208 阅读 · 0 评论 -
23. Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 合并k个有序的链表,我们假设每个链表的平均长度是n。#include "MergeKSortedLists.h"//方法一:两两合并ListNode* MergeKSortedLists::mergeK原创 2017-09-26 22:48:52 · 328 阅读 · 0 评论 -
24. Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head.For example, Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. You may no原创 2017-10-08 18:02:26 · 272 阅读 · 0 评论 -
25. 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.k is a positive integer and is less than or equal to the length of the linked list. If the number of nod原创 2017-10-08 21:36:46 · 281 阅读 · 0 评论 -
26. Remove Duplicates from Sorted Array
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place with cons原创 2017-10-09 00:31:47 · 199 阅读 · 0 评论 -
27. Remove Element
Given an array and a value, remove all instances of that value in place and return the new length.Do not allocate extra space for another array, you must do this in place with constant memory.The order原创 2017-10-09 01:19:23 · 233 阅读 · 0 评论 -
28. Implement strStr()
Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. 实现strStr()函数。 返回needle在haystack中第一次出现的位置,若needle不在其中则返回-1.方法一:int Implement原创 2017-10-10 08:40:09 · 218 阅读 · 0 评论 -
44. 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原创 2017-11-25 18:32:28 · 342 阅读 · 0 评论