From dec84ca5a08de5b486c155d7515e229b942da717 Mon Sep 17 00:00:00 2001 From: Openset Date: 2019年1月14日 15:08:51 +0800 Subject: [PATCH] Add: new --- README.md | 6 +- problems/k-closest-points-to-origin/README.md | 56 ++++++++++++ problems/largest-perimeter-triangle/README.md | 67 ++++++++++++++ problems/odd-even-jump/README.md | 88 +++++++++++++++++++ .../subarray-sums-divisible-by-k/README.md | 37 ++++++++ 5 files changed, 253 insertions(+), 1 deletion(-) create mode 100644 problems/k-closest-points-to-origin/README.md create mode 100644 problems/largest-perimeter-triangle/README.md create mode 100644 problems/odd-even-jump/README.md create mode 100644 problems/subarray-sums-divisible-by-k/README.md diff --git a/README.md b/README.md index 048396455..9097b39ef 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,10 @@ LeetCode Problems' Solutions | # | Title | Solution | Difficulty | | :-: | - | - | :-: | +| 976 | [Largest Perimeter Triangle](https://leetcode.com/problems/largest-perimeter-triangle "三角形的最大周长") | [Go](https://github.com/openset/leetcode/tree/master/problems/largest-perimeter-triangle) | Easy | +| 975 | [Odd Even Jump](https://leetcode.com/problems/odd-even-jump "奇偶跳") | [Go](https://github.com/openset/leetcode/tree/master/problems/odd-even-jump) | Hard | +| 974 | [Subarray Sums Divisible by K](https://leetcode.com/problems/subarray-sums-divisible-by-k "和可被 K 整除的子数组") | [Go](https://github.com/openset/leetcode/tree/master/problems/subarray-sums-divisible-by-k) | Medium | +| 973 | [K Closest Points to Origin](https://leetcode.com/problems/k-closest-points-to-origin "最接近原点的 K 个点") | [Go](https://github.com/openset/leetcode/tree/master/problems/k-closest-points-to-origin) | Easy | | 972 | [Equal Rational Numbers](https://leetcode.com/problems/equal-rational-numbers "相等的有理数") | [Go](https://github.com/openset/leetcode/tree/master/problems/equal-rational-numbers) | Hard | | 971 | [Flip Binary Tree To Match Preorder Traversal](https://leetcode.com/problems/flip-binary-tree-to-match-preorder-traversal "翻转二叉树以匹配先序遍历") | [Go](https://github.com/openset/leetcode/tree/master/problems/flip-binary-tree-to-match-preorder-traversal) | Medium | | 970 | [Powerful Integers](https://leetcode.com/problems/powerful-integers "强整数") | [Go](https://github.com/openset/leetcode/tree/master/problems/powerful-integers) | Easy | @@ -989,7 +993,7 @@ LeetCode Problems' Solutions | 33 | [Search in Rotated Sorted Array](https://leetcode.com/problems/search-in-rotated-sorted-array "搜索旋转排序数组") | [Go](https://github.com/openset/leetcode/tree/master/problems/search-in-rotated-sorted-array) | Medium | | 32 | [Longest Valid Parentheses](https://leetcode.com/problems/longest-valid-parentheses "最长有效括号") | [Go](https://github.com/openset/leetcode/tree/master/problems/longest-valid-parentheses) | Hard | | 31 | [Next Permutation](https://leetcode.com/problems/next-permutation "下一个排列") | [Go](https://github.com/openset/leetcode/tree/master/problems/next-permutation) | Medium | -| 30 | [Substring with Concatenation of All Words](https://leetcode.com/problems/substring-with-concatenation-of-all-words "与所有单词相关联的字串") | [Go](https://github.com/openset/leetcode/tree/master/problems/substring-with-concatenation-of-all-words) | Hard | +| 30 | [Substring with Concatenation of All Words](https://leetcode.com/problems/substring-with-concatenation-of-all-words "串联所有单词的子串") | [Go](https://github.com/openset/leetcode/tree/master/problems/substring-with-concatenation-of-all-words) | Hard | | 29 | [Divide Two Integers](https://leetcode.com/problems/divide-two-integers "两数相除") | [Go](https://github.com/openset/leetcode/tree/master/problems/divide-two-integers) | Medium | | 28 | [Implement strStr()](https://leetcode.com/problems/implement-strstr "实现strStr()") | [Go](https://github.com/openset/leetcode/tree/master/problems/implement-strstr) | Easy | | 27 | [Remove Element](https://leetcode.com/problems/remove-element "移除元素") | [Go](https://github.com/openset/leetcode/tree/master/problems/remove-element) | Easy | diff --git a/problems/k-closest-points-to-origin/README.md b/problems/k-closest-points-to-origin/README.md new file mode 100644 index 000000000..b66f2ab3b --- /dev/null +++ b/problems/k-closest-points-to-origin/README.md @@ -0,0 +1,56 @@ + + + + + + + +## 973. K Closest Points to Origin (Easy) + +

We have a list of points on the plane. Find the K closest points to the origin (0, 0).

+ +

(Here, the distance between two points on a plane is the Euclidean distance.)

+ +

You may return the answer in any order. The answer is guaranteed to be unique (except for the order that it is in.)

+ + + +
+

Example 1:

+ +
+Input: points = [[1,3],[-2,2]], K = 1
+Output: [[-2,2]]
+Explanation: 
+The distance between (1, 3) and the origin is sqrt(10).
+The distance between (-2, 2) and the origin is sqrt(8).
+Since sqrt(8) < sqrt(10), (-2, 2) is closer to the origin.
+We only want the closest K = 1 points from the origin, so the answer is just [[-2,2]].
+
+ +
+

Example 2:

+ +
+Input: points = [[3,3],[5,-1],[-2,4]], K = 2
+Output: [[3,3],[-2,4]]
+(The answer [[-2,4],[3,3]] would also be accepted.)
+
+ + + +

Note:

+ +
    +
  1. 1 <= K <= points.length <= 10000
  2. +
  3. -10000 < points[i][0] < 10000
  4. +
  5. -10000 < points[i][1] < 10000
  6. +
+
+
+ + +### Related Topics + [[Sort](https://github.com/openset/leetcode/tree/master/tag/sort/README.md)] + [[Math](https://github.com/openset/leetcode/tree/master/tag/math/README.md)] + [[Divide and Conquer](https://github.com/openset/leetcode/tree/master/tag/divide-and-conquer/README.md)] diff --git a/problems/largest-perimeter-triangle/README.md b/problems/largest-perimeter-triangle/README.md new file mode 100644 index 000000000..7a61f2f82 --- /dev/null +++ b/problems/largest-perimeter-triangle/README.md @@ -0,0 +1,67 @@ + + + + + + + +## 976. Largest Perimeter Triangle (Easy) + +

Given an array A of positive lengths, return the largest perimeter of a triangle with non-zero area, formed from 3 of these lengths.

+ +

If it is impossible to form any triangle of non-zero area, return 0.

+ + + +
    +
+ +
+

Example 1:

+ +
+Input: [2,1,2]
+Output: 5
+
+ +
+

Example 2:

+ +
+Input: [1,2,1]
+Output: 0
+
+ +
+

Example 3:

+ +
+Input: [3,2,3,4]
+Output: 10
+
+ +
+

Example 4:

+ +
+Input: [3,6,2,3]
+Output: 8
+
+ + + +

Note:

+ +
    +
  1. 3 <= A.length <= 10000
  2. +
  3. 1 <= A[i] <= 10^6
  4. +
+
+
+
+
+ + +### Related Topics + [[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)] + [[Math](https://github.com/openset/leetcode/tree/master/tag/math/README.md)] diff --git a/problems/odd-even-jump/README.md b/problems/odd-even-jump/README.md new file mode 100644 index 000000000..72f438c82 --- /dev/null +++ b/problems/odd-even-jump/README.md @@ -0,0 +1,88 @@ + + + + + + + +## 975. Odd Even Jump (Hard) + +

You are given an integer array A. From some starting index, you can make a series of jumps. The (1st, 3rd, 5th, ...) jumps in the series are called odd numbered jumps, and the (2nd, 4th, 6th, ...) jumps in the series are called even numbered jumps.

+ +

You may from index i jump forward to index j (with i < j) in the following way:

+ + + +

A starting index is good if, starting from that index, you can reach the end of the array (index A.length - 1) by jumping some number of times (possibly 0 or more than once.)

+ +

Return the number of good starting indexes.

+ + + +

Example 1:

+ +
+Input: [10,13,12,14,15]
+Output: 2
+Explanation: 
+From starting index i = 0, we can jump to i = 2 (since A[2] is the smallest among A[1], A[2], A[3], A[4] that is greater or equal to A[0]), then we can't jump any more.
+From starting index i = 1 and i = 2, we can jump to i = 3, then we can't jump any more.
+From starting index i = 3, we can jump to i = 4, so we've reached the end.
+From starting index i = 4, we've reached the end already.
+In total, there are 2 different starting indexes (i = 3, i = 4) where we can reach the end with some number of jumps.
+
+ +
+

Example 2:

+ +
+Input: [2,3,1,1,4]
+Output: 3
+Explanation: 
+From starting index i = 0, we make jumps to i = 1, i = 2, i = 3:
+
+During our 1st jump (odd numbered), we first jump to i = 1 because A[1] is the smallest value in (A[1], A[2], A[3], A[4]) that is greater than or equal to A[0].
+
+During our 2nd jump (even numbered), we jump from i = 1 to i = 2 because A[2] is the largest value in (A[2], A[3], A[4]) that is less than or equal to A[1]. A[3] is also the largest value, but 2 is a smaller index, so we can only jump to i = 2 and not i = 3.
+
+During our 3rd jump (odd numbered), we jump from i = 2 to i = 3 because A[3] is the smallest value in (A[3], A[4]) that is greater than or equal to A[2].
+
+We can't jump from i = 3 to i = 4, so the starting index i = 0 is not good.
+
+In a similar manner, we can deduce that:
+From starting index i = 1, we jump to i = 4, so we reach the end.
+From starting index i = 2, we jump to i = 3, and then we can't jump anymore.
+From starting index i = 3, we jump to i = 4, so we reach the end.
+From starting index i = 4, we are already at the end.
+In total, there are 3 different starting indexes (i = 1, i = 3, i = 4) where we can reach the end with some number of jumps.
+
+ +
+

Example 3:

+ +
+Input: [5,1,3,4,2]
+Output: 3
+Explanation: 
+We can reach the end from starting indexes 1, 2, and 4.
+
+
+
+ + + +

Note:

+ +
    +
  1. 1 <= A.length <= 20000
  2. +
  3. 0 <= A[i] < 100000
  4. +
+ + +### Related Topics + [[Stack](https://github.com/openset/leetcode/tree/master/tag/stack/README.md)] + [[Dynamic Programming](https://github.com/openset/leetcode/tree/master/tag/dynamic-programming/README.md)] diff --git a/problems/subarray-sums-divisible-by-k/README.md b/problems/subarray-sums-divisible-by-k/README.md new file mode 100644 index 000000000..c7f35ea53 --- /dev/null +++ b/problems/subarray-sums-divisible-by-k/README.md @@ -0,0 +1,37 @@ + + + + + + + +## 974. Subarray Sums Divisible by K (Medium) + +

Given an array A of integers, return the number of (contiguous, non-empty) subarrays that have a sum divisible by K.

+ + + +
+

Example 1:

+ +
+Input: A = [4,5,0,-2,-3,1], K = 5
+Output: 7
+Explanation: There are 7 subarrays with a sum divisible by K = 5:
+[4, 5, 0, -2, -3, 1], [5], [5, 0], [5, 0, -2, -3], [0], [0, -2, -3], [-2, -3]
+
+ + + +

Note:

+ +
    +
  1. 1 <= A.length <= 30000
  2. +
  3. -10000 <= A[i] <= 10000
  4. +
  5. 2 <= K <= 10000
  6. +
+
+ + +### Related Topics + [[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]

AltStyle によって変換されたページ (->オリジナル) /