Quantcast
Channel: 书影 - Entries for the tag leetcode
Browsing all 559 articles
Browse latest View live

[LeetCode]Shortest Path Visiting All Nodes

题目描述:LeetCode 847. Shortest Path Visiting All NodesAn undirected, connected graph of N nodes (labeled 0, 1, 2, ..., N-1) is given as graph.graph.length = N, and j != i is in the list graph[i] exactly...

View Article


[LeetCode]Car Fleet

题目描述:LeetCode 853. Car FleetN cars are going to the same destination along a one lane road.  The destination is target miles away.Each car i has a constant speed speed[i] (in miles per hour), and...

View Article


[LeetCode]Exam Room

题目描述:LeetCode 855. Exam RoomIn an exam room, there are N seats in a single row, numbered 0, 1, 2, ..., N-1.When a student enters the room, they must sit in the seat that maximizes the distance to the...

View Article

[LeetCode]K-Similar Strings

题目描述:LeetCode 854. K-Similar StringsStrings A and B are K-similar (for some non-negative integer K) if we can swap the positions of two letters in A exactly K times so that the resulting string equals...

View Article

[LeetCode]Advantage Shuffle

题目描述:LeetCode 870. Advantage ShuffleGiven two arrays A and B of equal size, the advantage of A with respect to B is the number of indices i for which A[i] > B[i].Return any permutation of A that...

View Article


[LeetCode]Minimum Number of Refueling Stops

题目描述:LeetCode 871. Minimum Number of Refueling StopsA car travels from a starting position to a destination which is target miles east of the starting position.Along the way, there are gas stations....

View Article

[LeetCode]Koko Eating Bananas

题目描述:LeetCode 875. Koko Eating BananasKoko loves to eat bananas.  There are N piles of bananas, the i-th pile has piles[i] bananas.  The guards have gone and will come back in H hours.Koko can decide...

View Article

[LeetCode]Length of Longest Fibonacci Subsequence

题目描述:LeetCode 873. Length of Longest Fibonacci SubsequenceA sequence X_1, X_2, ..., X_n is fibonacci-like if:n >= 3X_i + X_{i+1} = X_{i+2} for all i + 2 <= nGiven a strictly increasing array A of...

View Article


Image may be NSFW.
Clik here to view.

[LeetCode]Largest Component Size by Common Factor

题目描述:LeetCode 952. Largest Component Size by Common FactorGiven a non-empty array of unique positive integers A, consider the following graph:There are A.length nodes, labelled A[0] to A[A.length -...

View Article


[LeetCode]Reveal Cards In Increasing Order

题目描述:LeetCode 950. Reveal Cards In Increasing OrderIn 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...

View Article

[LeetCode]Numbers With Repeated Digits

题目描述:LeetCode 1015. Numbers With Repeated DigitsGiven a positive integer N, return the number of positive integers less than or equal to N that have at least 1 repeated digit.Example 1:Input: 20Output:...

View Article

[LeetCode]Capacity To Ship Packages Within D Days

题目描述:LeetCode 1014. Capacity To Ship Packages Within D DaysA 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...

View Article

[LeetCode]Convert to Base -2

题目描述:LeetCode 1017. Convert to Base -2Given a number N, return a string consisting of "0"s and "1"s that represents its value in base -2 (negative two).The returned string must have no leading zeroes,...

View Article


[LeetCode]Next Greater Node In Linked List

题目描述:LeetCode 1019. Next Greater Node In Linked ListWe are given a linked list with head as the first node.  Let's number the nodes in the list: node_1, node_2, node_3, ... etc.Each node may have a...

View Article

[LeetCode]Print in Order

题目描述:LeetCode 1114. Print in OrderSuppose we have a class: public class Foo {  public void first() { print("first"); }  public void second() { print("second"); }  public void third() { print("third");...

View Article


[LeetCode]Print FooBar Alternately

题目描述:LeetCode 1115. Print FooBar AlternatelySuppose you are given the following code: class FooBar { public void foo() {    for (int i = 0; i < n; i++) {      print("foo");  } } public void bar() {...

View Article

Image may be NSFW.
Clik here to view.

[LeetCode]Optimize Water Distribution in a Village

题目描述:LeetCode 1168. Optimize Water Distribution in a VillageThere are n houses in a village. We want to supply water for all the houses by building wells and laying pipes.For each house i, we can...

View Article


[LeetCode]Minimum Number of Frogs Croaking

题目描述:LeetCode 1419. Minimum Number of Frogs CroakingGiven the string croakOfFrogs, which represents a combination of the string "croak" from different frogs, that is, multiple frogs can croak at the...

View Article

[LeetCode]Constrained Subsequence Sum

题目描述: Given an integer array nums and an integer k, return the maximum sum of a non-empty subsequence of that array such that for every two consecutive integers in the subsequence, nums[i] and nums[j],...

View Article
Browsing all 559 articles
Browse latest View live