diff --git a/problems/length-of-last-word/README.md b/problems/length-of-last-word/README.md index 6c2c9726a..dd318bee1 100644 --- a/problems/length-of-last-word/README.md +++ b/problems/length-of-last-word/README.md @@ -11,18 +11,20 @@ ## 58. Length of Last Word (Easy) -
Given a string s consists of upper/lower-case alphabets and empty space characters ' '
, return the length of last word in the string.
Given a string s consists of upper/lower-case alphabets and empty space characters ' '
, return the length of last word in the string.
If the last word does not exist, return 0.
Note: A word is defined as a character sequence consists of non-space characters only.
-Example: +
Example:
+-Input: "Hello World" +Input: "Hello World" Output: 5- + +
### Related Topics [[String](https://github.com/openset/leetcode/tree/master/tag/string/README.md)] diff --git a/problems/maximum-sum-of-3-non-overlapping-subarrays/README.md b/problems/maximum-sum-of-3-non-overlapping-subarrays/README.md index bae2645de..ca1541185 100644 --- a/problems/maximum-sum-of-3-non-overlapping-subarrays/README.md +++ b/problems/maximum-sum-of-3-non-overlapping-subarrays/README.md @@ -11,29 +11,32 @@ ## 689. Maximum Sum of 3 Non-Overlapping Subarrays (Hard) -
-In a given array nums
of positive integers, find three non-overlapping subarrays with maximum sum.
-
-Each subarray will be of size k
, and we want to maximize the sum of all 3*k
entries.
-
-Return the result as a list of indices representing the starting position of each interval (0-indexed). If there are multiple answers, return the lexicographically smallest one. -
-Example:
+
In a given array nums
of positive integers, find three non-overlapping subarrays with maximum sum.
Each subarray will be of size k
, and we want to maximize the sum of all 3*k
entries.
Return the result as a list of indices representing the starting position of each interval (0-indexed). If there are multiple answers, return the lexicographically smallest one.
+ +Example:
+Input: [1,2,1,2,6,7,5,1], 2 Output: [0, 3, 5] Explanation: Subarrays [1, 2], [2, 6], [7, 5] correspond to the starting indices [0, 3, 5]. We could have also taken [2, 1], but an answer of [1, 3, 5] would be lexicographically larger.- -
Note:
-
nums.length
will be between 1 and 20000.nums[i]
will be between 1 and 65535.k
will be between 1 and floor(nums.length / 3).+ +
Note:
+ +nums.length
will be between 1 and 20000.nums[i]
will be between 1 and 65535.k
will be between 1 and floor(nums.length / 3).### Related Topics [[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)] diff --git a/problems/minimize-malware-spread/README.md b/problems/minimize-malware-spread/README.md index 90462e403..f290c09c0 100644 --- a/problems/minimize-malware-spread/README.md +++ b/problems/minimize-malware-spread/README.md @@ -26,28 +26,25 @@
Example 1:
-Input: graph = [[1,1,0],[1,1,0],[0,0,1]], initial = [0,1] -Output: 0 +Input: graph = [[1,1,0],[1,1,0],[0,0,1]], initial = [0,1] +Output: 0-
Example 2:
-Input: graph = [[1,0,0],[0,1,0],[0,0,1]], initial = [0,2] -Output: 0 +Input: graph = [[1,0,0],[0,1,0],[0,0,1]], initial = [0,2] +Output: 0-
Example 3:
-Input: graph = [[1,1,1],[1,1,1],[1,1,1]], initial = [1,2] -Output: 1 +Input: graph = [[1,1,1],[1,1,1],[1,1,1]], initial = [1,2] +Output: 1
@@ -61,9 +58,6 @@
1 <= initial.length < graph.length
0 <= initial[i] < graph.length
In the computer world, use restricted resource you have to generate maximum benefit is what we always want to pursue.
+For now, suppose you are a dominator of m 0s
and n 1s
respectively. On the other hand, there is an array with strings consisting of only 0s
and 1s
.
-Now your task is to find the maximum number of strings that you can form with given m 0s
and n 1s
. Each 0
and 1
can be used at most once.
-
Now your task is to find the maximum number of strings that you can form with given m 0s
and n 1s
. Each 0
and 1
can be used at most once.
Note:
-Note:
0s
and 1s
will both not exceed 100
600
.0s
and 1s
will both not exceed 100
600
.Example 1:
+
+ +
Example 1:
+-Input: Array = {"10", "0001", "111001", "1", "0"}, m = 5, n = 3 +Input: Array = {"10", "0001", "111001", "1", "0"}, m = 5, n = 3 Output: 4 -Explanation: This are totally 4 strings can be formed by the using of 5 0s and 3 1s, which are “10,”0001”,”1”,”0” +Explanation: This are totally 4 strings can be formed by the using of 5 0s and 3 1s, which are “10,”0001”,”1”,”0”- -
Example 2:
+
+ +
Example 2:
+-Input: Array = {"10", "0", "1"}, m = 1, n = 1 +Input: Array = {"10", "0", "1"}, m = 1, n = 1 Output: 2 -Explanation: You could form "10", but then you'd have nothing left. Better form "0" and "1". +Explanation: You could form "10", but then you'd have nothing left. Better form "0" and "1".- + +
### Related Topics [[Dynamic Programming](https://github.com/openset/leetcode/tree/master/tag/dynamic-programming/README.md)] diff --git a/problems/pyramid-transition-matrix/README.md b/problems/pyramid-transition-matrix/README.md index 49424836a..7fecb2c1c 100644 --- a/problems/pyramid-transition-matrix/README.md +++ b/problems/pyramid-transition-matrix/README.md @@ -11,49 +11,52 @@ ## 756. Pyramid Transition Matrix (Medium) -
-We are stacking blocks to form a pyramid. Each block has a color which is a one letter string, like `'Z'`. -
-For every block of color `C` we place not in the bottom row, we are placing it on top of a left block of color `A` and right block of color `B`. We are allowed to place the block there only if `(A, B, C)` is an allowed triple. -
-We start with a bottom row of bottom
, represented as a single string. We also start with a list of allowed triples allowed
. Each allowed triple is represented as a string of length 3.
-
-Return true if we can build the pyramid all the way to the top, otherwise false. -
- -Example 1:
+
We are stacking blocks to form a pyramid. Each block has a color which is a one letter string.
+ +We are allowed to place any color block C
on top of two adjacent blocks of colors A
and B
, if and only if ABC
is an allowed triple.
We start with a bottom row of bottom
, represented as a single string. We also start with a list of allowed triples allowed
. Each allowed triple is represented as a string of length 3.
Return true if we can build the pyramid all the way to the top, otherwise false.
+ +Example 1:
+-Input: bottom = "XYZ", allowed = ["XYD", "YZE", "DEA", "FFF"] +Input: bottom = "BCD", allowed = ["BCG", "CDE", "GEA", "FFF"] Output: true Explanation: We can stack the pyramid like this: A / \ - D E + G E / \ / \ -X Y Z +B C D -This works because ('X', 'Y', 'D'), ('Y', 'Z', 'E'), and ('D', 'E', 'A') are allowed triples. -- +We are allowed to place G on top of B and C because BCG is an allowed triple. Similarly, we can place E on top of C and D, then A on top of G and E. + +
+ +
Example 2:
-Example 2:
-Input: bottom = "XXYX", allowed = ["XXX", "XXY", "XYX", "XYY", "YXZ"] +Input: bottom = "AABA", allowed = ["AAA", "AAB", "ABA", "ABB", "BAC"] Output: false Explanation: -We can't stack the pyramid to the top. +We can't stack the pyramid to the top. Note that there could be allowed triples (A, B, C) and (A, B, D) with C != D.- -
Note:
+
+ +
Note:
+bottom
will be a string with length in range [2, 8]
.allowed
will have length in range [0, 200]
.{'A', 'B', 'C', 'D', 'E', 'F', 'G'}
.bottom
will be a string with length in range [2, 8]
.allowed
will have length in range [0, 200]
.{'A', 'B', 'C', 'D', 'E', 'F', 'G'}
.### Related Topics [[Bit Manipulation](https://github.com/openset/leetcode/tree/master/tag/bit-manipulation/README.md)] diff --git a/problems/uncrossed-lines/README.md b/problems/uncrossed-lines/README.md index e98122140..39f75ec9e 100644 --- a/problems/uncrossed-lines/README.md +++ b/problems/uncrossed-lines/README.md @@ -13,7 +13,14 @@
We write the integers of A
and B
(in the order they are given) on two separate horizontal lines.
Now, we may draw a straight line connecting two numbers A[i]
and B[j]
as long as A[i] == B[j]
, and the line we draw does not intersect any other connecting (non-horizontal) line.
Now, we may draw connecting lines: a straight line connecting two numbers A[i]
and B[j]
such that:
A[i] == B[j]
;Note that a connecting lines cannot intersect even at the endpoints: each number can only belong to one connecting line.
Return the maximum number of connecting lines we can draw in this way.
diff --git a/problems/valid-square/README.md b/problems/valid-square/README.md index a348d6bd9..c45abb907 100644 --- a/problems/valid-square/README.md +++ b/problems/valid-square/README.md @@ -15,20 +15,24 @@The coordinate (x,y) of a point is represented by an integer array with two integers.
-Example:
+
Example:
+Input: p1 = [0,0], p2 = [1,1], p3 = [1,0], p4 = [0,1] Output: True- -
Note: +
+ +
Note:
+### Related Topics [[Math](https://github.com/openset/leetcode/tree/master/tag/math/README.md)]