leetcode中等
光行天下
学生-工作了
展开
-
【linked-java】426.Convert Binary Search Tree to Sorted Doubly Linked List
Convert a BST to a sorted circular doubly-linked list in-place. Think of the left and right pointers as synonymous to the previous and next pointers in a doubly-linked list.Let’s take the following B...原创 2020-04-08 12:21:08 · 181 阅读 · 0 评论 -
【linked-java】369.Plus One Linked List
Given a non-negative number represented as a singly linked list of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list.Example:Input...原创 2020-04-08 01:24:21 · 194 阅读 · 0 评论 -
【array-java】1011. Capacity To Ship Packages Within D Days
A conveyor belt has packages that must be shipped from one port to another within D days.The i-th package on the conveyor belt has a weight of weights[i]. Each day, we load the ship with packages on...原创 2020-03-23 16:27:17 · 239 阅读 · 0 评论 -
【array-java】835. Image Overlap
Two images A and B are given, represented as binary, square matrices of the same size. (A binary matrix has only 0s and 1s as values.)We translate one image however we choose (sliding it left, right...原创 2020-03-23 15:43:29 · 212 阅读 · 0 评论 -
【array-java】1267. Count Servers that Communicate
You are given a map of a server center, represented as a m * n integer matrix grid, where 1 means that on that cell there is a server and 0 means that it is no server. Two servers are said to communic...原创 2020-03-23 15:19:35 · 155 阅读 · 0 评论 -
【array-java】78. Subsets
Given a set of distinct integers, 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],[1],[2],...原创 2020-03-23 15:01:52 · 148 阅读 · 0 评论 -
【array-java】1151. Minimum Swaps to Group All 1's Together - Medium
Given a binary array data, return the minimum number of swaps required to group all 1’s present in the array together in any placein the array.Example 1:Input: [1,0,1,0,1]Output: 1Explanation:The...原创 2020-03-23 14:48:31 · 174 阅读 · 0 评论 -
【array-java】531. Lonely Pixel I
Given a picture consisting of black and white pixels, find the number of black lonely pixels.The picture is represented by a 2D char array consisting of ‘B’ and ‘W’, which means black and white pixel...原创 2020-03-23 09:35:46 · 200 阅读 · 0 评论 -
【array-java】238. Product of Array Except Self
Given an array nums of n integers where n > 1, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Example:Input: [1,2,3,4]Output: [24...原创 2020-03-23 09:27:13 · 131 阅读 · 0 评论 -
【array-java】1375. Bulb Switcher III
There is a room with n bulbs, numbered from 1 to n, arranged in a row from left to right. Initially, all the bulbs are turned off.At moment k (for k from 0 to n - 1), we turn on the light[k] bulb. A ...原创 2020-03-22 15:39:26 · 203 阅读 · 0 评论 -
【array-java】370. Range Addition
Assume you have an array of length n initialized with all 0’s and are given k update operations.Each operation is represented as a triplet: [startIndex, endIndex, inc] which increments each element o...原创 2020-03-22 14:54:46 · 115 阅读 · 0 评论 -
【array-java】282.Wiggle Sort
Given an unsorted array nums, reorder it in-place such that nums[0] <= nums[1] >= nums[2] <= nums[3]…For example, given nums = [3, 5, 2, 1, 6, 4], one possible answer is [1, 6, 2, 5, 3, 4]....原创 2020-03-22 14:44:28 · 119 阅读 · 0 评论 -
【array-java】1343. Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold
Given an array of integers arr and two integers k and threshold.Return the number of sub-arrays of size k and average greater than or equal to threshold.Example 1:Input: arr = [2,2,2,2,5,5,5,8], k ...原创 2020-03-22 14:25:42 · 186 阅读 · 0 评论 -
[array-java]442.Find All Duplicates in an Array
Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements that appear twice in this array.Could you do it without extra sp...原创 2020-03-22 13:49:08 · 119 阅读 · 0 评论 -
【java-array】969. Pancake Sorting
Given an array A, we can perform a pancake flip: We choose some positive integer k <= A.length, then reverse the order of the first k elements of A. We want to perform zero or more pancake flips (...原创 2020-03-22 13:02:28 · 165 阅读 · 0 评论 -
【java-array】1338. Reduce Array Size to The Half
Given an array arr. You can choose a set of integers and remove all the occurrences of these integers in the array.Return the minimum size of the set so that at least half of the integers of the arr...原创 2020-03-19 16:41:07 · 250 阅读 · 0 评论 -
【java-array】723. Candy Crush 糖果消消乐
This question is about implementing a basic elimination algorithm for Candy Crush.Given a 2D integer array board representing the grid of candy, different positive integers board[i][j] represent diff...原创 2020-03-12 13:47:59 · 465 阅读 · 0 评论 -
【java-array】1222. Queens That Can Attack the King
On an 8x8 chessboard, there can be multiple Black Queens and one White King.Given an array of integer coordinates queens that represents the positions of the Black Queens, and a pair of coordinates k...原创 2020-03-09 11:08:17 · 233 阅读 · 0 评论 -
【java-np】1277. Count Square Submatrices with All Ones
Given a m * n matrix of ones and zeros, return how many square submatrices have all ones.Example 1:Input: matrix =[[0,1,1,1],[1,1,1,1],[0,1,1,1]]Output: 15Explanation:There are 10 squares of...原创 2020-03-09 10:01:15 · 271 阅读 · 0 评论 -
【java】950. Reveal Cards In Increasing Order
In a deck of cards, every card has a unique integer. You can order the deck in any order you want.Initially, all the cards start face down (unrevealed) in one deck.Now, you do the following steps r...原创 2020-03-09 09:37:27 · 151 阅读 · 0 评论 -
【java】1329. Sort the Matrix Diagonally
Given a m * n matrix mat of integers, sort it diagonally in ascending order from the top-left to the bottom-right then return the sorted array.Example 1:Input: mat = [[3,3,1,1],[2,2,1,2],[1,1,1,2]]...原创 2020-03-08 14:24:18 · 204 阅读 · 0 评论 -
【java】535. Encode and Decode TinyURL
Note: This is a companion problem to the System Design problem: Design TinyURL.TinyURL is a URL shortening service where you enter a URL such as https://leetcode.com/problems/design-tinyurl and it r...原创 2020-03-08 10:38:08 · 229 阅读 · 0 评论 -
【java】701. Insert into a Binary Search Tree
Given the root node of a binary search tree (BST) and a value to be inserted into the tree, insert the value into the BST. Return the root node of the BST after the insertion. It is guaranteed that th...原创 2020-03-08 08:44:51 · 158 阅读 · 0 评论 -
【java】1038. Binary Search Tree to Greater Sum Tree
Given the root of a binary search tree with distinct values, modify it so that every node has a new value equal to the sum of the values of the original tree that are greater than or equal to node.val...原创 2020-03-08 08:34:52 · 140 阅读 · 0 评论 -
【java】807. Max Increase to Keep City Skyline
In a 2 dimensional array grid, each value grid[i][j] represents the height of a building located there. We are allowed to increase the height of any number of buildings, by any amount (the amounts can...原创 2020-03-08 08:25:31 · 162 阅读 · 0 评论 -
1302. Deepest Leaves Sum
Given a binary tree, return the sum of values of its deepest leaves.Example 1:Input: root = [1,2,3,4,5,null,6,7,null,null,null,null,8]Output: 15Constraints:The number of nodes in the tree is bet...原创 2020-03-07 23:52:00 · 207 阅读 · 0 评论 -
1315. Sum of Nodes with Even-Valued Grandparent
Given a binary tree, return the sum of values of nodes with even-valued grandparent. (A grandparent of a node is the parent of its parent, if it exists.)If there are no nodes with an even-valued gra...原创 2020-03-07 23:24:57 · 223 阅读 · 0 评论 -
1282. Group the People Given the Group Size They Belong To
There are n people whose IDs go from 0 to n - 1 and each person belongs exactly to one group. Given the array groupSizes of length n telling the group size each person belongs to, return the groups th...原创 2020-03-07 22:40:44 · 140 阅读 · 0 评论 -
1265.Print Immutable Linked List in Reverse【java】
反转链表,该链表为单链表。public class Solution { public ListNode reverse(ListNode head) { ListNode prev = null; while (head != null) { ListNode temp = head.next; ...原创 2020-03-07 21:23:30 · 236 阅读 · 0 评论