LeetCode题目
文章平均质量分 67
zc2985716963
这个作者很懒,什么都没留下…
展开
-
LeetCode#210 Course Schedule II(C++版)
题干:There are a total of n courses you have to take, labeled from 0 to n - 1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expr原创 2017-09-24 23:28:03 · 357 阅读 · 0 评论 -
LeetCode#98. Validate Binary Search Tree
题目: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原创 2017-11-26 17:05:26 · 139 阅读 · 0 评论 -
LeetCode#92. Reverse Linked List II
题目:Reverse a linked list from position m to n. Do it in-place and in one-pass.For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL.Note:Given m, n sati原创 2017-12-22 18:56:43 · 174 阅读 · 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"]原创 2017-12-22 19:04:16 · 152 阅读 · 0 评论 -
LeetCode#94. Binary Tree Inorder Traversal
题目:Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree [1,null,2,3],return [1,3,2].Note: Recursive solution is trivial, could y原创 2017-12-06 20:04:00 · 143 阅读 · 0 评论 -
LeetCode#62. Unique Paths
题意: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 r原创 2017-12-17 21:53:25 · 152 阅读 · 0 评论 -
证明STINGY SAT是NP-complete问题
要证明要这个问题之前,我们先来回顾一下,什么是SAT问题,以下概念摘自课本算法概论(注释版)。对于一般的SAT来说,给定一个有穷的布尔变量集合X = {X1,X2,,,,,,,Xn}, |X| = n,每个变量取值0或1,一组字句C = C1∩C2∩.......交Cn,每个Ci是由多个变量组成的析取范式,长度不限,即Z1 ∨Z2∨Z3∨...........∨Zn。问:给定一个布尔变量集合X原创 2018-01-03 19:43:06 · 1095 阅读 · 0 评论 -
LeetCode#91. Decode Ways
题目:A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine th原创 2017-12-28 16:57:35 · 191 阅读 · 0 评论 -
LeetCode#90. Subsets II
题目:Given a collection of integers that might contain duplicates, nums, return all possible subsets (the power set).Note: The solution set must not contain duplicate subsets.For example,原创 2017-12-28 17:16:26 · 179 阅读 · 0 评论 -
LeetCode#96Unique Binary Search Trees
题目:Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's.题意解析:这道题目是给定一个整数n,寻找按照从1到n原创 2017-11-26 16:16:56 · 157 阅读 · 0 评论 -
LeetCode#48. Rotate Image
题目:You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Note:You have to rotate the image in-place, which means you have to modify the inpu原创 2017-12-01 23:26:18 · 179 阅读 · 0 评论 -
Leetcode#15. 3Sum
题目:Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note: The solution set must not原创 2017-10-16 21:13:28 · 137 阅读 · 0 评论 -
LeetCode#46 Permutation
题意:Given 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],原创 2017-10-09 10:10:23 · 274 阅读 · 0 评论 -
LeetCode#3.Longest Substring Without Repeating Characters
题目要求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 th原创 2017-09-17 13:10:26 · 233 阅读 · 0 评论 -
Leetcode#17. Letter Combinations of a Phone Number
题意题目解析:一道字符串匹配的问题,就是模拟平常用九宫格手机短信的时候,输入为一串数字,然后找出每个数字对应的所有可能,算法如下:申请vecotr result,用来存放最终结果。申请vector tmp用来存放临时结果,输入为一串数字digits1.第一步因result是空的,将digits[0]所具有的所有字符分别成串放进result中2.第二部对每个result中的结原创 2017-10-19 10:39:46 · 173 阅读 · 0 评论 -
Leetcode#49. Group Anagrams
题目:Given an array of strings, group anagrams together.For example, given: ["eat", "tea", "tan", "ate", "nat", "bat"], Return:Note: All inputs will be in lower-case.题意:对字符串集进行分类的一原创 2017-10-27 20:52:44 · 164 阅读 · 0 评论 -
LeetCode#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 p原创 2017-10-28 11:34:03 · 170 阅读 · 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:[ "((()))", "(()())", "(())(原创 2017-10-21 00:06:28 · 161 阅读 · 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原创 2017-10-09 11:11:38 · 163 阅读 · 0 评论 -
LeetCode#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 Both num1 and num2 contains on原创 2017-10-15 19:10:49 · 173 阅读 · 0 评论 -
LeetCode#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.De原创 2017-12-28 17:28:36 · 139 阅读 · 0 评论