![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LEETCODE
文章平均质量分 65
其实系一个须刨
这个作者很懒,什么都没留下…
展开
-
java排序算法
class Solution { void sort(int[] arr) { boolean remain = false; for (int i = 0; i < arr.length; i++) { for (int j = 0; j < arr.length - i - 1; j++) { if (arr[j] < arr[j + 1]) { ..原创 2021-06-05 01:18:42 · 59 阅读 · 0 评论 -
1. Two Sum
Given an array of integers numsand an integer target, return indices of the two numbers such that they add up to target.You may assume that each input would have exactly one solution, and you may not use the same element twice.You can return the answe.原创 2021-05-20 21:01:37 · 59 阅读 · 0 评论 -
845. Longest Mountain in Array
You may recall that an array arr is a mountain array if and only if:arr.length >= 3There exists some index i (0-indexed) with 0 < i < arr.length - 1 such that:arr[0] < arr[1] < ... < arr[i - 1] < arr[i]arr[i] > arr[i + 1] >原创 2021-05-06 21:02:12 · 76 阅读 · 0 评论 -
838. Push Dominoes
There areN dominoes in a line, and we place each domino vertically upright.In the beginning, we simultaneously pushsome of the dominoes either to the left or to the right.After each second, each domino that is falling to the left pushes the adjacent ..原创 2021-04-19 20:05:25 · 124 阅读 · 0 评论 -
820. Short Encoding of Words
A valid encoding of an array of words is any reference string s and array of indices indices such that:words.length == indices.lengthThe reference string s ends with the '#' character.For each index indices[i], the substring of s starting from indices[原创 2021-03-29 19:59:34 · 62 阅读 · 0 评论 -
813. Largest Sum of Averages
We partition a row of numbers Ainto at most K adjacent (non-empty) groups, then our score is the sum of the average of each group. What is the largest score we can achieve?Note that our partition must use every number in A, and that scores are not neces.原创 2021-03-26 19:57:14 · 93 阅读 · 0 评论 -
808. Soup Servings
There are two types of soup: type A and type B. Initially we have N ml of each type of soup. There are four kinds of operations:Serve100 ml of soup A and 0 ml of soup BServe75 ml of soup A and 25ml of soup BServe 50 ml of soup A and 50 ml of soup B...原创 2021-03-24 17:26:45 · 120 阅读 · 0 评论 -
802. Find Eventual Safe States
We start at some node in a directed graph, and every turn, we walk along a directed edge of the graph. If we reach a terminal node (that is, it has no outgoing directed edges), we stop.We define a starting node to be safe if we must eventually walk to a原创 2021-03-22 20:32:46 · 69 阅读 · 0 评论 -
801. Minimum Swaps To Make Sequences Increasing
We have two integer sequences A and B of the same non-zero length.We are allowed to swap elements A[i] and B[i].Note that both elements are in the same index position in their respective sequences.At the end of some number of swaps, A and B are both ..原创 2021-03-20 19:08:47 · 75 阅读 · 0 评论 -
799. Champagne Tower
We stack glasses in a pyramid, where the first row has 1 glass, the second row has 2 glasses, and so on until the 100th row.Each glass holds one cupof champagne.Then, some champagne is poured into the first glass at the top.When the topmost glass is...原创 2021-03-20 19:09:01 · 87 阅读 · 0 评论 -
795. Number of Subarrays with Bounded Maximum
We are given an array A of positive integers, and two positive integers L and R (L <= R).Return the number of (contiguous, non-empty) subarrays such that the value of the maximum array element in that subarray is at least L and at most R.Example :I原创 2021-03-18 19:13:15 · 72 阅读 · 0 评论 -
790. Domino and Tromino Tiling
We have two types of tiles: a 2x1 domino shape, and an "L" tromino shape. These shapes may be rotated.XX <- dominoXX <- "L" trominoXGiven N, how many ways are there to tile a 2 x N board? Return your answer modulo 10^9 + 7.(In a tiling, eve..原创 2021-01-27 15:00:51 · 135 阅读 · 0 评论 -
781. Rabbits in Forest
In a forest, each rabbit has some color. Some subset of rabbits (possibly all of them) tell you how many other rabbits have the same color as them. Thoseanswersare placed in an array.Return the minimum number of rabbits that could be in the forest...原创 2021-01-15 20:23:47 · 95 阅读 · 0 评论 -
779. K-th Symbol in Grammar
On the first row, we write a 0. Now in every subsequent row, we look at the previous row and replace each occurrence of 0 with 01, and each occurrence of 1 with 10.Given row N and index K, return the K-th indexed symbol in row N. (The values of K are 1-i原创 2021-01-15 19:38:40 · 104 阅读 · 0 评论 -
775. Global and Local Inversions
We have some permutation A of [0, 1, ..., N - 1], where N is the length of A.The number of (global) inversions is the number of i < j with 0 <= i < j < N and A[i] > A[j].The number of local inversions is the number of i with 0 <= i ..原创 2021-01-13 11:37:28 · 62 阅读 · 0 评论 -
754. Reach a Number
You are standing at position 0 on an infinite number line. There is a goal at position target.On each move, you can either go left or right. During the n-th move (starting from 1), you take n steps.Return the minimum number of steps required to reach t原创 2021-01-08 17:57:49 · 96 阅读 · 0 评论 -
721. Accounts Merge
Given a list accounts, each element accounts[i] is a list of strings, where the first element accounts[i][0] is a name, and the rest of the elements are emails representing emails of the account.Now, we would like to merge these accounts. Two accounts de原创 2021-01-05 21:40:29 · 119 阅读 · 0 评论 -
714. Best Time to Buy and Sell Stock with Transaction Fee
Your are given an array of integers prices, for which the i-th element is the price of a given stock on day i; and a non-negative integer fee representing a transaction fee.You may complete as many transactions as you like, but you need to pay the transa原创 2020-12-30 16:51:24 · 55 阅读 · 0 评论 -
713. Subarray Product Less Than K
713. Subarray Product Less Than K难度中等208收藏分享切换为中文接收动态反馈Your are given an array of positive integersnums.Count and print the number of (contiguous) subarrays where the product of all the elements in the subarray is less thank.Example 1:Input:...原创 2020-12-30 15:43:23 · 59 阅读 · 0 评论 -
688. Knight Probability in Chessboard
On an NxN chessboard, a knight starts at the r-th row and c-th column and attempts to make exactly K moves. The rows and columns are 0 indexed, so the top-left square is (0, 0), and the bottom-right square is (N-1, N-1).A chess knight has 8 possible move原创 2020-12-26 20:34:34 · 67 阅读 · 0 评论 -
687. Longest Univalue Path
Given the root of a binary tree, return the length of the longest path, where each node in the path has the same value. This path may or may not pass through the root.The length of the path between two nodes is represented by the number of edges between原创 2020-12-26 19:40:32 · 67 阅读 · 0 评论 -
684. Redundant Connection
In this problem, a tree is an undirected graph that is connected and has no cycles.The given input is a graph that started as a tree with N nodes (with distinct values 1, 2, ..., N), with one additional edge added. The added edge has two different vertic原创 2020-12-23 23:49:17 · 103 阅读 · 1 评论 -
678. Valid Parenthesis String
Given a string containing only three types of characters: '(', ')' and '*', write a function to check whether this string is valid. We define the validity of a string by these rules:Any left parenthesis '(' must have a corresponding right parenthesis ')'原创 2020-12-23 16:12:15 · 79 阅读 · 0 评论 -
673. Number of Longest Increasing Subsequence
Given an integer arraynums, return the number of longest increasing subsequences.Notice that the sequence has to be strictly increasing.Example 1:Input: nums = [1,3,5,4,7]Output: 2Explanation: The two longest increasing subsequences are [1, 3, ..原创 2020-12-16 22:46:14 · 101 阅读 · 0 评论 -
672. Bulb Switcher II
There is a room with n lights which are turned on initially and 4 buttons on the wall. After performing exactly m unknown operations towards buttons, you need to return how many different kinds of status of the n lights could be.Suppose n lights are labe原创 2020-12-16 17:46:30 · 60 阅读 · 1 评论 -
662. Maximum Width of Binary Tree
Given a binary tree, write a function to get the maximum width of the given tree. The maximum width of a tree is the maximum width among all levels.The width of one level is defined as the length between the end-nodes (the leftmost and right most non-nul原创 2020-12-10 23:42:58 · 104 阅读 · 0 评论 -
659. Split Array into Consecutive Subsequences
Given an array numssorted in ascending order, return true if and only if you can split it into 1 or more subsequences such that each subsequence consists of consecutive integersand has length at least 3.Example 1:Input: [1,2,3,3,4,5]Output: True...原创 2020-12-08 00:02:00 · 84 阅读 · 0 评论 -
655. Print Binary Tree
Print a binary tree in an m*n 2D string array following these rules:The row number m should be equal to the height of the given binary tree.The column number n should always be an odd number.The root node's value (in string format) should be put in the原创 2020-12-04 09:26:33 · 69 阅读 · 0 评论 -
652. Find Duplicate Subtrees
Given the rootof a binary tree, return all duplicate subtrees.For each kind of duplicate subtrees, you only need to return the root node of any one of them.Two trees are duplicate if they have the same structure with the same node values.Example 1:.原创 2020-11-22 23:01:53 · 66 阅读 · 0 评论 -
650. 2 Keys Keyboard
Initially on a notepad only one character 'A' is present. You can perform two operations on this notepad for each step:Copy All: You can copy all the characters present on the notepad (partial copy is not allowed).Paste: You can paste the characters whi原创 2020-11-22 14:49:36 · 64 阅读 · 0 评论 -
649. Dota2 Senate
Dota2 的世界里有两个阵营:Radiant(天辉)和Dire(夜魇)Dota2 参议院由来自两派的参议员组成。现在参议院希望对一个 Dota2 游戏里的改变作出决定。他们以一个基于轮为过程的投票进行。在每一轮中,每一位参议员都可以行使两项权利中的一项:禁止一名参议员的权利:参议员可以让另一位参议员在这一轮和随后的几轮中丧失所有的权利。宣布胜利:如果参议员发现有权利投票的参议员都是同一个阵营的,他可以宣布胜利并决定在游戏中的有关变化。给定一个字符串代表每...原创 2020-11-22 14:16:13 · 200 阅读 · 0 评论 -
647. Palindromic Substrings
Given a string, your task is to count how many palindromic substrings in this string.The substrings with different start indexes or end indexes are counted as different substrings even they consist of same characters.Example 1:Input: "abc"Output: 3原创 2020-11-20 09:26:30 · 70 阅读 · 0 评论 -
646. Maximum Length of Pair Chain
ou are given n pairs of numbers. In every pair, the first number is always smaller than the second number.Now, we define a pair (c, d) can follow another pair (a, b) if and only if b < c. Chain of pairs can be formed in this fashion.Given a set of p原创 2020-11-15 23:48:25 · 77 阅读 · 0 评论 -
638. Shopping Offers
In LeetCode Store, there are some kinds of items to sell. Each item has a price.However, there are some special offers, and a special offer consists of one or more different kinds of items with a sale price.You are given the each item's price, a set of原创 2020-11-15 22:47:41 · 64 阅读 · 0 评论 -
636. Exclusive Time of Functions
On a single-threaded CPU, we execute a program containing n functions. Each function has a unique ID between 0 and n-1.Function calls are stored in a call stack: when a function call starts, its ID is pushed onto the stack, and when a function call ends,原创 2020-11-13 20:11:32 · 117 阅读 · 0 评论 -
621. Task Scheduler
Given a characters array tasks, representing the tasks a CPU needs to do, where each letter represents a different task. Tasks could be done in any order. Each task is done in one unit of time. For each unit of time, the CPU could complete either one task原创 2020-11-10 21:08:25 · 86 阅读 · 0 评论 -
576. Out of Boundary Paths
There is an m by n grid with a ball. Given the start coordinate (i,j) of the ball, you can move the ball to adjacent cell or cross the grid boundary in four directions (up, down, left, right). However, you can at most move N times. Find out the number of p原创 2020-11-09 17:44:28 · 153 阅读 · 0 评论 -
560. Subarray Sum Equals K
Given an array of integers nums and an integer k, return the total number of continuous subarrays whose sum equals to k.Example 1:Input: nums = [1,1,1], k = 2Output: 2Example 2:Input: nums = [1,2,3], k = 3Output: 2来源:力扣(LeetCode)链接:https://leet原创 2020-11-08 18:14:13 · 115 阅读 · 0 评论 -
556. Next Greater Element III
Given a positive 32-bit integer n, you need to find the smallest 32-bit integer which has exactly the same digits existing in the integer n and is greater in value than n. If no such positive 32-bit integer exists, you need to return -1.Example 1:Input原创 2020-11-02 21:02:29 · 73 阅读 · 0 评论 -
538. Convert BST to Greater Tree
Given the root of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all keys greater than the original key in BST.As a reminder, a binary search tree is a tree that原创 2020-10-30 20:04:48 · 101 阅读 · 0 评论