Medium
weixin_39145266
这个作者很懒,什么都没留下…
展开
-
742 Closest Leaf in a Binary Tree
1 题目Given a binary treewhere every node has a unique value, and a target keyk, find the value of the nearest leaf node to targetkin the tree.Here,nearestto a leaf means the least number of e...原创 2020-01-06 10:44:09 · 128 阅读 · 0 评论 -
314 Binary Tree Vertical Order Traversal
1 题目Given a binary tree, return thevertical ordertraversal of its nodes' values. (ie, from top to bottom, column by column).If two nodes are in the same row and column, the order should be from...原创 2020-01-06 06:52:23 · 113 阅读 · 0 评论 -
1223 Dice Roll Simulation
1 题目A die simulator generates a random number from 1 to 6 for each roll.You introduced a constraint to the generator such that it cannot roll the numberimore thanrollMax[i](1-indexed)consecuti...原创 2019-12-24 05:24:18 · 295 阅读 · 0 评论 -
1155 Number of Dice Rolls With Target Sum
1 题目You haveddice, and each die hasffaces numbered1, 2, ..., f.Return the number of possible ways (out offdtotal ways)modulo10^9 + 7to roll the dice so the sum of the face up numbers equ...原创 2019-12-18 10:47:23 · 151 阅读 · 0 评论 -
348 Design Tic-Tac-Toe
1 题目Design a Tic-tac-toe game that is played between two players on anxngrid.You may assume the following rules:A move is guaranteed to be valid and is placed on an empty block. Once a winn...原创 2019-12-05 10:55:19 · 132 阅读 · 0 评论 -
253 Meeting Rooms II
1 题目Given an array of meeting time intervals consisting of start and end times[[s1,e1],[s2,e2],...](si< ei), find the minimum number of conference rooms required.Example 1:Input: [[0, 30]...原创 2019-12-05 07:06:08 · 56 阅读 · 0 评论 -
957 Prison Cells After N Days
1 题目There are 8 prison cells in a row, and each cell is either occupied or vacant.Each day, whether the cell is occupied or vacant changes according to the following rules:If a cell has two adja...原创 2019-12-01 07:40:28 · 93 阅读 · 0 评论 -
1167 Minimum Cost to Connect Sticks
1 题目You have somestickswithpositive integer lengths.You can connect any two sticks of lengthsXandYinto one stickby paying a cost ofX + Y. You perform this action until there is one stick...原创 2019-12-01 05:31:19 · 165 阅读 · 0 评论 -
1104 Path In Zigzag Labelled Binary Tree
1 题目In an infinite binary tree where every node has two children, the nodes are labelled in row order.In the odd numbered rows (ie., the first, third, fifth,...), the labelling is left to right, w...原创 2019-11-26 14:33:59 · 88 阅读 · 0 评论 -
1143 Longest Common Subsequence
1 题目Given two stringstext1andtext2, return the length of their longest common subsequence.Asubsequenceof a string is a new string generated from the original string with some characters(can b...原创 2019-11-26 13:54:20 · 91 阅读 · 0 评论 -
692 Top K Frequent Words
1 题目Given a non-empty list of words, return thekmost frequent elements.Your answer should be sorted by frequency from highest to lowest. If two words have the same frequency, then the word with ...原创 2019-11-26 12:54:55 · 49 阅读 · 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 评论 -
5 Longest Palindromic Substring
1 题目Given a strings, find the longest palindromic substring ins. You may assume that the maximum length ofsis 1000.Example 1:Input: "babad"Output: "bab"Note: "aba" is also a valid answer....原创 2019-03-29 09:16:34 · 54 阅读 · 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 · 58 阅读 · 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 评论