leetcode每日一题202003
Bryan要加油
这个作者很懒,什么都没留下…
展开
-
543. Diameter of Binary Tree(Leetcode每日一题-2020.03.10)
ProblemGiven a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any two nodes in a tree. This path may ...原创 2020-01-16 19:47:29 · 148 阅读 · 0 评论 -
1013. Partition Array Into Three Parts With Equal Sum(Leetcode每日一题-2020.03.11)
ProblemGiven an array A of integers, return true if and only if we can partition the array into three non-empty parts with equal sums.Formally, we can partition the array if we can find indexes i+1 ...原创 2020-03-11 23:22:13 · 162 阅读 · 0 评论 -
322. Coin Change(Leetcode每日一题-2020.03.08)
ProblemYou are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount o...原创 2020-03-08 11:15:05 · 229 阅读 · 0 评论 -
121. Best Time to Buy and Sell Stock(Leetcode每日一题-2020.03.09)
ProblemSay you have an array for which the ith\ i^th ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (i.e., buy one and s...原创 2020-03-09 21:03:19 · 239 阅读 · 0 评论 -
面试题57 - II. 和为s的连续正数序列(Leetcode每日一题-2020.03.06)
Problem输入一个正整数 target ,输出所有和为 target 的连续正整数序列(至少含有两个数)。序列内的数字由小到大排列,不同序列按照首个数字从小到大排列。限制:1 <= target <= 10^5Example1输入:target = 9输出:[[2,3,4],[4,5]]Example2输入:target = 15输出:[[1,2,3,4,5...原创 2020-03-06 19:19:26 · 172 阅读 · 0 评论 -
1103. Distribute Candies to People(Leetcode每日一题-2020.03.05)
ProblemWe distribute some number of candies, to a row of n = num_people people in the following way:We then give 1 candy to the first person, 2 candies to the second person, and so on until we give ...原创 2020-03-05 19:44:00 · 172 阅读 · 0 评论 -
面试题 10.01. Sorted Merge LCCI(Leetcode每日一题-2020.03.03)
ProblemYou are given two sorted arrays, A and B, where A has a large enough buffer at the end to hold B. Write a method to merge B into A in sorted order.Initially the number of elements in A and B ...原创 2020-03-03 20:23:01 · 240 阅读 · 0 评论 -
225. Implement Stack using Queues(Leetcode每日一题-2020.03.01)
ProblemImplement the following operations of a stack using queues.push(x) – Push element x onto stack.pop() – Removes the element on top of the stack.top() – Get the top element.empty() – Return...原创 2020-03-08 11:33:39 · 160 阅读 · 0 评论 -
912. Sort an Array(Leetcode每日一题-2020.03.31)
ProblemGiven an array of integers nums, sort the array in ascending order.Example1Input: nums = [5,2,3,1]Output: [1,2,3,5]Example2Input: nums = [5,1,1,2,0,0]Output: [0,0,1,1,2,5]SolutionS...原创 2020-03-31 20:43:38 · 215 阅读 · 0 评论 -
面试题62. 圆圈中最后剩下的数字(Leetcode每日一题-2020.03.30)
Problem0,1,n-1这n个数字排成一个圆圈,从数字0开始,每次从这个圆圈里删除第m个数字。求出这个圆圈里剩下的最后一个数字。例如,0、1、2、3、4这5个数字组成一个圆圈,从数字0开始每次删除第3个数字,则删除的前4个数字依次是2、0、4、1,因此最后剩下的数字是3。Example1输入: n = 5, m = 3输出: 3Example2输入: n = 10, m =...原创 2020-03-30 20:13:22 · 344 阅读 · 0 评论 -
1162. As Far from Land as Possible(Leetcode每日一题-2020.03.29)
ProblemGiven an N x N grid containing only values 0 and 1, where 0 represents water and 1 represents land, find a water cell such that its distance to the nearest land cell is maximized and return th...原创 2020-03-30 20:05:56 · 318 阅读 · 0 评论 -
820. Short Encoding of Words(Leetcode每日一题-2020.03.28)
ProblemGiven a list of words, we may encode it by writing a reference string S and a list of indexes A.For example, if the list of words is [“time”, “me”, “bell”], we can write it as S = “time#bell#...原创 2020-03-30 19:57:51 · 275 阅读 · 0 评论 -
914. X of a Kind in a Deck of Cards(Leetcode每日一题-2020.03.27)
ProblemIn a deck of cards, each card has an integer written on it.Return true if and only if you can choose X >= 2 such that it is possible to split the entire deck into 1 or more groups of cards...原创 2020-03-27 20:57:16 · 227 阅读 · 0 评论 -
面试题59 - II. 队列的最大值(Leetcode每日一题-2020.03.07)
Problem请定义一个队列并实现函数 max_value 得到队列里的最大值,要求函数max_value、push_back 和 pop_front 的均摊时间复杂度都是O(1)。若队列为空,pop_front 和 max_value 需要返回 -1Example1输入:[“MaxQueue”,“push_back”,“push_back”,“max_value”,“pop_fron...原创 2020-03-07 22:02:36 · 211 阅读 · 0 评论 -
999. Available Captures for Rook(Leetcode每日一题-2020.03.26)
ProblemOn an 8 x 8 chessboard, there is one white rook. There also may be empty squares, white bishops, and black pawns. These are given as characters ‘R’, ‘.’, ‘B’, and ‘p’ respectively. Uppercase...原创 2020-03-26 20:06:11 · 272 阅读 · 0 评论 -
994. Rotting Oranges(Leetcode每日一题-2020.03.04)
ProblemIn a given grid, each cell can have one of three values:the value 0 representing an empty cell;the value 1 representing a fresh orange;the value 2 representing a rotten orange.Every minu...原创 2020-03-04 19:52:26 · 273 阅读 · 0 评论 -
206. Reverse Linked List(Leetcode每日一题-2020.03.02)
ProblemReverse a singly linked list.ExampleInput: 1->2->3->4->5->NULLOutput: 5->4->3->2->1->NULLSolutionSolution1三指针迭代/** * Definition for singly-linked list....原创 2020-03-02 20:19:24 · 148 阅读 · 0 评论 -
892. Surface Area of 3D Shapes(Leetcode每日一题-2020.03.25)
ProblemOn a N * N grid, we place some 1 * 1 * 1 cubes.Each value v = grid[i][j] represents a tower of v cubes placed on top of grid cell (i, j).Return the total surface area of the resulting shapes...原创 2020-03-25 20:20:24 · 316 阅读 · 0 评论 -
面试题 17.16. The Masseuse LCCI(Leetcode每日一题-2020.03.24)
ProblemA popular masseuse receives a sequence of back-to-back appointment requests and is debating which ones to accept. She needs a break between appointments and therefore she cannot accept any adj...原创 2020-03-24 23:17:19 · 720 阅读 · 0 评论 -
876. Middle of the Linked List(Leetcode每日一题-2020.03.23)
ProblemGiven a non-empty, singly linked list with head node head, return a middle node of linked list.If there are two middle nodes, return the second middle node.Note:The number of nodes in the g...原创 2020-03-23 19:48:37 · 191 阅读 · 0 评论 -
945. Minimum Increment to Make Array Unique(Leetcode每日一题-2020.03.22)
ProblemGiven an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.Return the least number of moves to make every value in A unique.Note:0 <= A.length <= 400...原创 2020-03-22 17:20:40 · 212 阅读 · 0 评论 -
365. Water and Jug Problem(Leetcode每日一题-2020.03.21)
You are given two jugs with capacities x and y litres. There is an infinite amount of water supply available. You need to determine whether it is possible to measure exactly z litres using these two j...原创 2020-03-21 15:24:29 · 314 阅读 · 0 评论 -
面试题40. 最小的k个数(Leetcode每日一题-2020.03.20)
Problem输入整数数组 arr ,找出其中最小的 k 个数。例如,输入4、5、1、6、2、7、3、8这8个数字,则最小的4个数字是1、2、3、4。限制:0 <= k <= arr.length <= 100000 <= arr[i] <= 10000Example1输入:arr = [3,2,1], k = 2输出:[1,2] 或者 [2,1]...原创 2020-03-20 19:27:57 · 201 阅读 · 0 评论 -
409. Longest Palindrome(Leetcode每日一题-2020.03.19)
ProblemGiven a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters.This is case sensitive, for example “Aa” is no...原创 2020-03-19 20:04:14 · 166 阅读 · 0 评论 -
836. Rectangle Overlap(Leetcode每日一题-2020.03.18)
ProblemA rectangle is represented as a list [x1, y1, x2, y2], where (x1, y1) are the coordinates of its bottom-left corner, and (x2, y2) are the coordinates of its top-right corner.Two rectangles ov...原创 2020-03-18 19:47:45 · 181 阅读 · 0 评论 -
1160. Find Words That Can Be Formed by Characters(Leetcode每日一题-2020.03.17)
ProblemYou are given an array of strings words and a string chars.A string is good if it can be formed by characters from chars (each character can only be used once).Return the sum of lengths of a...原创 2020-03-17 19:55:19 · 220 阅读 · 0 评论 -
面试题 01.06. Compress String LCCI(Leetcode每日一题-2020.03.16)
ProblemImplement a method to perform basic string compression using the counts of repeated characters. For example, the string aabcccccaaa would become a2blc5a3. If the “compressed” string would not ...原创 2020-03-16 19:30:26 · 225 阅读 · 0 评论 -
695. Max Area of Island(Leetcode每日一题-2020.03.15)
ProblemGiven a non-empty 2D array grid of 0’s and 1’s, an island is a group of 1’s (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid ar...原创 2020-03-15 23:01:19 · 187 阅读 · 0 评论 -
300. Longest Increasing Subsequence(Leetcode每日一题-2020.03.14)
ProblemGiven an unsorted array of integers, find the length of longest increasing subsequence.Note:There may be more than one LIS combination, it is only necessary for you to return the length.You...原创 2020-03-14 22:43:35 · 416 阅读 · 0 评论 -
169. Majority Element(Leetcode每日一题-2020.03.13)
ProblemGiven an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority eleme...原创 2020-03-13 21:43:04 · 167 阅读 · 0 评论 -
1071. Greatest Common Divisor of Strings(Leetcode每日一题-2020.03.12)
ProblemFor strings S and T, we say “T divides S” if and only if S = T + … + T (T concatenated with itself 1 or more times)Return the largest string X such that X divides str1 and X divides str2.Ex...原创 2020-03-12 19:45:09 · 230 阅读 · 0 评论