![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
[LeetCode 刷题]
文章平均质量分 58
「已注销」
这个作者很懒,什么都没留下…
展开
-
[leetcode 3] Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For原创 2015-01-07 19:53:56 · 233 阅读 · 0 评论 -
[leetcode 29] Divide Two Integers
Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.class Solution {public: int divide(int dividend, int divisor) { if (d原创 2015-01-07 19:55:16 · 202 阅读 · 0 评论 -
[leetcode 75] 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-01-06 20:37:36 · 260 阅读 · 0 评论 -
[leetcode 56] 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 Interva原创 2015-01-06 21:18:39 · 193 阅读 · 0 评论 -
[leetcode 148] Sort List
Sort a linked list in O(n log n) time using constant space complexity./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : v原创 2015-01-06 12:40:44 · 241 阅读 · 0 评论 -
[leetcode 49] Anagrams
Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.class Solution {public: vector anagrams(vector &strs) { const int原创 2015-01-07 09:45:00 · 224 阅读 · 0 评论 -
[leetcode 57] 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-01-06 21:56:28 · 264 阅读 · 0 评论 -
[leetcode 164] Maximum Gap
Given an unsorted array, find the maximum difference between the successive elements in its sorted form.Try to solve it in linear time/space.Return 0 if the array contains less than 2 elements原创 2015-01-06 22:39:40 · 273 阅读 · 0 评论 -
[leetcode 21] Merge Two Sorted Lists
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists./** * Definition for singly-linked list. * struct ListN原创 2015-01-06 11:30:46 · 169 阅读 · 0 评论 -
[leetcode 147] Insertion Sort List
Sort a linked list using insertion sort./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */原创 2015-01-06 21:37:12 · 289 阅读 · 0 评论 -
[leetcode 30] Substring with Concatenation of All Words
You are given a string, S, and a list of words, L, that are all of the same length. Find all starting indices of substring(s) in S that is a concatenation of each word in L exactly once and without原创 2015-01-08 17:51:26 · 215 阅读 · 0 评论 -
[leetcode 39] Combination Sum
Given a set of candidate numbers (C) 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 unlimited numb原创 2015-01-08 23:39:58 · 277 阅读 · 0 评论 -
[leetcode 77] Combinations
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.For example,If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4],]原创 2015-01-09 10:17:56 · 264 阅读 · 0 评论 -
[leetcode 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 combina原创 2015-01-09 00:00:55 · 442 阅读 · 0 评论 -
[leetcode 174] Dungeon Game
The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a 2D grid. Our valiant knight (K) was initially p原创 2015-01-09 09:21:49 · 406 阅读 · 0 评论 -
[leetcode 76] Minimum Window Substring
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S = "ADOBECODEBANC"T = "ABC"Minimum window is "BAN原创 2015-01-08 20:07:08 · 323 阅读 · 0 评论 -
[leetcode 136] Single Number
Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using e原创 2015-01-07 23:00:40 · 192 阅读 · 0 评论 -
[leetcode 137] Single Number II
Given an array of integers, every element appears three times except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without u原创 2015-01-07 23:03:21 · 232 阅读 · 0 评论 -
[leetcode 166] Fraction to Recurring Decimal
Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.If the fractional part is repeating, enclose the repeating part in parentheses.原创 2015-01-08 12:32:15 · 372 阅读 · 0 评论 -
[leetcode 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 '.'.A partially fille原创 2015-01-08 21:07:00 · 219 阅读 · 0 评论 -
[leetcode 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:"((()))", "(()())", "(())()", "()(())", "()()原创 2015-01-09 11:06:40 · 179 阅读 · 0 评论 -
[leetcode 17] Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.Input:Digit st原创 2015-01-09 11:27:09 · 301 阅读 · 0 评论 -
[leetcode 51] 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.原创 2015-01-11 09:54:53 · 220 阅读 · 0 评论 -
[leetcode 52] N-Queens II
Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.class Solution {public: int totalNQueens(int n) { this原创 2015-01-11 09:58:03 · 252 阅读 · 0 评论 -
[leetcode 78] Subsets
Given a set of distinct integers, S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.For exa原创 2015-01-11 14:22:47 · 225 阅读 · 0 评论 -
[leetcode 90] Subsets II
Given a collection of integers that might contain duplicates, S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain dupli原创 2015-01-11 14:41:58 · 197 阅读 · 0 评论 -
[leetcode 79] Word Search
Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically原创 2015-01-11 15:37:50 · 381 阅读 · 0 评论 -
[leetcode 131] Palindrome Partitioning
Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s = "aab",Return [ ["aa","原创 2015-01-11 10:31:27 · 260 阅读 · 0 评论 -
[leetcode 47] 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-01-11 11:22:03 · 203 阅读 · 0 评论 -
[leetcode 46] Permutations
Given a collection of 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], and [3,2,1].class Solution原创 2015-01-11 10:40:00 · 341 阅读 · 0 评论 -
[leetcode 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-01-11 11:25:29 · 234 阅读 · 0 评论 -
[leetcode 2] Add Two Numbers
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a link原创 2014-12-28 08:07:32 · 273 阅读 · 0 评论 -
[leetcode 49] Anagrams
Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.class Solution {public: vector anagrams(vector &strs) { unordered_ma原创 2014-12-30 23:10:15 · 328 阅读 · 0 评论 -
[leetcode 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, and there exists one unique longest palindromic substring.思路: 从当前位置向两边扩展cl原创 2015-01-11 19:34:44 · 332 阅读 · 0 评论 -
[leetcode 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 NA P L S I原创 2015-01-11 21:32:09 · 221 阅读 · 0 评论 -
[leetcode 9] Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.class Solution {public: bool isPalindrome(int x) { if (x < 0) { return false; } int原创 2015-01-11 22:43:54 · 199 阅读 · 0 评论 -
[leetcode 11] 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原创 2015-01-11 23:16:42 · 187 阅读 · 0 评论 -
[leetcode 14] Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.class Solution {public: string longestCommonPrefix(vector &strs) { const int m = strs.size();原创 2015-01-11 23:34:11 · 221 阅读 · 0 评论 -
[leetcode 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.A sudoku原创 2015-01-11 17:00:22 · 215 阅读 · 0 评论 -
[leetcode 10] 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 st原创 2015-01-11 17:14:59 · 211 阅读 · 0 评论