LeetCode
weixin_39145266
这个作者很懒,什么都没留下…
展开
-
946 Validate Stack Sequences
1 题目Given two sequencespushedandpoppedwith distinct values,returntrueif and only if this could have been the result of a sequence of push and pop operations on an initially empty stack.Example 1:Input: pushed = [1,2,3,4,5], popped = [4,5,3,2,...原创 2020-07-14 12:10:09 · 138 阅读 · 0 评论 -
59 Spiral Matrix II
1 题目Given a positive integern, generate a square matrix filled with elements from 1 ton2in spiral order.Example:Input: 3Output:[ [ 1, 2, 3 ], [ 8, 9, 4 ], [ 7, 6, 5 ]]2 尝试解class S...原创 2019-03-29 09:18:46 · 48 阅读 · 0 评论 -
142 Linked List Cycle II
1 题目Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull.To represent a cycle in the given linked list, we use an integerposwhich represents the positio...原创 2019-03-29 15:21:34 · 55 阅读 · 0 评论 -
56 Merge Intervals
1 题目Given a collection of intervals, merge all overlapping intervals.Example 1:Input: [[1,3],[2,6],[8,10],[15,18]]Output: [[1,6],[8,10],[15,18]]Explanation: Since intervals [1,3] and [2,6] ov...原创 2019-03-29 09:17:13 · 47 阅读 · 0 评论 -
48 Rotate Image
1 题目You are given annxn2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Note:You have to rotate the imagein-place, which means you have to modify the input 2D ma...原创 2019-03-29 09:15:51 · 49 阅读 · 0 评论 -
61 Rotate List
1 题目Given a linkedlist, rotate the list to the right bykplaces, wherekis non-negative.2 尝试解class Solution {public: ListNode* rotateRight(ListNode* head, int k) { if(head == NU...原创 2019-03-29 09:16:15 · 41 阅读 · 0 评论 -
36 Valid Sudoku
1 题目Determine if a9x9 Sudoku boardis valid.Only the filled cells need to be validatedaccording to the following rules:Each rowmust contain thedigits1-9without repetition. Each column must...原创 2019-03-29 09:15:59 · 60 阅读 · 0 评论 -
8 String to Integer (atoi)
1 题目Implementatoiwhichconverts a string to an integer.The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting fr...原创 2019-03-29 09:16:08 · 58 阅读 · 0 评论 -
12 Integer to Roman
1 题目Roman numerals are represented by seven different symbols:I,V,X,L,C,DandM.Symbol ValueI 1V 5X 10L 50C 100D ...原创 2019-03-29 09:16:25 · 43 阅读 · 0 评论 -
92 Reverse Linked List II
1 题目Reverse a linked list from positionmton. Do it in one-pass.Note:1 ≤m≤n≤ length of list.Example:Input: 1->2->3->4->5->NULL, m = 2, n = 4Output: 1->4->3->2-...原创 2019-03-30 11:28:00 · 42 阅读 · 0 评论 -
209 Minimum Size Subarray Sum
1 题目Given an array ofnpositive integers and a positive integers, find the minimal length of acontiguoussubarray of which the sum ≥s. If there isn't one, return 0 instead.Example:Input: s...原创 2019-03-30 11:52:54 · 45 阅读 · 0 评论 -
287 Find the Duplicate Number
1 题目Given an arraynumscontainingn+ 1 integers where each integer is between 1 andn(inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate numbe...原创 2019-03-30 12:25:01 · 78 阅读 · 0 评论 -
62 Unique Paths
1 题目A robot is located at the top-left corner of amxngrid (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 reach ...原创 2019-03-29 09:19:17 · 60 阅读 · 0 评论 -
63 Unique Paths II
1 题目A robot is located at the top-left corner of amxngrid (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 reach ...原创 2019-03-29 09:16:42 · 59 阅读 · 0 评论 -
55 Jump Game
1 题目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.Determine...原创 2019-03-29 09:19:33 · 48 阅读 · 0 评论 -
49 Group Anagrams
1 题目Given an array of strings, group anagrams together.2 尝试解class Solution {public: vector<vector<string>> groupAnagrams(vector<string>& strs) { map<string...原创 2019-03-29 09:19:12 · 59 阅读 · 0 评论 -
94 Binary Tree Inorder Traversal
1 题目Given a binary tree, return theinordertraversal of its nodes' values.2 尝试解class Solution {public: vector<int> inorderTraversal(TreeNode* root) { vector<int> resul...原创 2019-03-29 09:19:02 · 54 阅读 · 0 评论 -
29 Divide Two Integers
1 题目Given two integersdividendanddivisor, divide two integers without using multiplication, division and mod operator.Return the quotient after dividingdividendbydivisor.The integer divisi...原创 2019-03-29 09:18:55 · 113 阅读 · 0 评论 -
75 Sort Colors
1 题目Given an array withnobjects colored red, white or blue, sort themin-placeso that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use ...原创 2019-03-29 09:17:19 · 79 阅读 · 0 评论 -
54 Spiral Matrix
1 题目Given a matrix ofmxnelements (mrows,ncolumns), return all elements of the matrix in spiral order.2 尝试解class Solution {public: vector<int> spiralOrder(vector<vector<i...原创 2019-03-29 09:18:50 · 61 阅读 · 0 评论 -
80 Remove Duplicates from Sorted Array II
1 题目Given a sorted arraynums, remove the duplicatesin-placesuch that duplicates appeared at mosttwiceand return the new length.Do not allocate extra space for another array, you must do this ...原创 2019-03-29 09:17:26 · 64 阅读 · 0 评论 -
6 ZigZag Conversion
1 题目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...原创 2019-03-29 09:17:34 · 56 阅读 · 0 评论 -
187 Repeated DNA Sequences
1 题目All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DNA....原创 2019-04-04 23:13:26 · 84 阅读 · 0 评论 -
274 H-Index
1 题目Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher's h-index.According to thedefinition of h-index on Wikipedia:...原创 2019-04-04 23:50:29 · 119 阅读 · 0 评论 -
299 Bulls and Cows
1 题目You are playing the followingBulls and Cowsgame with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide a hi...原创 2019-04-05 08:13:36 · 520 阅读 · 0 评论 -
64 Minimum Path Sum
1 题目Given amxngrid filled with non-negative numbers, find a path from top left to bottom right whichminimizesthe sum of all numbers along its path.Note:You can only move either down or righ...原创 2019-03-29 09:18:18 · 50 阅读 · 0 评论 -
22 Generate Parentheses
1 题目Givennpairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, givenn= 3, a solution set is:[ "((()))", "(()())", "(())()", "(...原创 2019-04-05 13:11:30 · 68 阅读 · 0 评论 -
151 Reverse Words in a String
1 题目Given an input string, reverse the string word by word.Example 1:Input: "the sky is blue"Output:"blue is sky the"Example 2:Input: " hello world! "Output:"world! hello"Explan...原创 2019-04-05 14:56:46 · 61 阅读 · 0 评论 -
114 Flatten Binary Tree to Linked List
1 题目Given a binary tree, flatten it to a linked list in-place.For example, given the following tree: 1 / \ 2 5 / \ \3 4 6The flattened tree should look like:1 \ 2 ...原创 2019-04-05 15:42:01 · 74 阅读 · 0 评论 -
46 Permutations
1 题目Given a collection of distinct integers, return all possible permutations.Example:Input: [1,2,3]Output:[ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]]2 尝试解class ...原创 2019-04-05 16:18:39 · 66 阅读 · 0 评论 -
73 Set Matrix Zeroes
1 题目Given amxnmatrix, if an element is 0, set its entire row and column to 0. Do itin-place.Example 1:Input: [ [1,1,1], [1,0,1], [1,1,1]]Output: [ [1,0,1], [0,0,0], [1,0,1]...原创 2019-03-29 09:18:33 · 49 阅读 · 0 评论 -
74 Search a 2D Matrix
1 题目Write an efficient algorithm that searches for a value in anmxnmatrix. This matrix has the following properties:Integers in each row are sorted from left to right. The first integer of ea...原创 2019-03-29 09:18:10 · 56 阅读 · 0 评论 -
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 ...原创 2019-04-10 15:28:30 · 68 阅读 · 0 评论 -
78 Subsets
1 题目Given a set ofdistinctintegers,nums, return all possible subsets (the power set).Note:The solution set must not contain duplicate subsets.Example:Input: nums = [1,2,3]Output:[ [3]...原创 2019-03-29 09:17:01 · 70 阅读 · 0 评论 -
93 Restore IP Addresses
1 题目Given a string containing only digits, restore it by returning all possible valid IP address combinations.Example:Input: "25525511135"Output: ["255.255.11.135", "255.255.111.35"]2 尝试解...原创 2019-04-10 16:48:09 · 62 阅读 · 0 评论 -
216 Combination Sum III
1 题目Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.Note:All number...原创 2019-04-10 17:38:39 · 72 阅读 · 0 评论 -
98 Validate Binary Search Tree
1 题目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 keysless thanthe node's key....原创 2019-04-01 17:49:11 · 56 阅读 · 0 评论 -
24 Swap Nodes in Pairs
1 题目Given alinked list, swap every two adjacent nodes and return its head.You maynotmodify the values in the list's nodes, only nodes itself may be changed.2 尝试解/** * Definition for singl...原创 2019-03-29 09:18:04 · 44 阅读 · 0 评论 -
105 Construct Binary Tree from Preorder and Inorder Traversal
1 题目Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.For example, givenpreorder =[3,9,20,15,7]inorder ...原创 2019-04-01 21:35:46 · 53 阅读 · 0 评论 -
106 Construct Binary Tree from Inorder and Postorder Traversal
1 题目Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.For example, giveninorder =[9,3,15,20,7]postorde...原创 2019-04-01 21:37:45 · 47 阅读 · 0 评论