Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 17d67f1

Browse files
author
Sandy
authored
Merge pull request #196 from openset/develop
Add: new
2 parents c610034 + dec84ca commit 17d67f1

File tree

5 files changed

+253
-1
lines changed

5 files changed

+253
-1
lines changed

‎README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ LeetCode Problems' Solutions
5353

5454
| # | Title | Solution | Difficulty |
5555
| :-: | - | - | :-: |
56+
| <span id="976">976</span> | [Largest Perimeter Triangle](https://leetcode.com/problems/largest-perimeter-triangle "三角形的最大周长") | [Go](https://github.com/openset/leetcode/tree/master/problems/largest-perimeter-triangle) | Easy |
57+
| <span id="975">975</span> | [Odd Even Jump](https://leetcode.com/problems/odd-even-jump "奇偶跳") | [Go](https://github.com/openset/leetcode/tree/master/problems/odd-even-jump) | Hard |
58+
| <span id="974">974</span> | [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 |
59+
| <span id="973">973</span> | [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 |
5660
| <span id="972">972</span> | [Equal Rational Numbers](https://leetcode.com/problems/equal-rational-numbers "相等的有理数") | [Go](https://github.com/openset/leetcode/tree/master/problems/equal-rational-numbers) | Hard |
5761
| <span id="971">971</span> | [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 |
5862
| <span id="970">970</span> | [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
989993
| <span id="33">33</span> | [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 |
990994
| <span id="32">32</span> | [Longest Valid Parentheses](https://leetcode.com/problems/longest-valid-parentheses "最长有效括号") | [Go](https://github.com/openset/leetcode/tree/master/problems/longest-valid-parentheses) | Hard |
991995
| <span id="31">31</span> | [Next Permutation](https://leetcode.com/problems/next-permutation "下一个排列") | [Go](https://github.com/openset/leetcode/tree/master/problems/next-permutation) | Medium |
992-
| <span id="30">30</span> | [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 |
996+
| <span id="30">30</span> | [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 |
993997
| <span id="29">29</span> | [Divide Two Integers](https://leetcode.com/problems/divide-two-integers "两数相除") | [Go](https://github.com/openset/leetcode/tree/master/problems/divide-two-integers) | Medium |
994998
| <span id="28">28</span> | [Implement strStr()](https://leetcode.com/problems/implement-strstr "实现strStr()") | [Go](https://github.com/openset/leetcode/tree/master/problems/implement-strstr) | Easy |
995999
| <span id="27">27</span> | [Remove Element](https://leetcode.com/problems/remove-element "移除元素") | [Go](https://github.com/openset/leetcode/tree/master/problems/remove-element) | Easy |
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author Openset <openset.wang@gmail.com> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
## 973. K Closest Points to Origin (Easy)
9+
10+
<p>We have a list of <code>points</code>&nbsp;on the plane.&nbsp; Find the <code>K</code> closest points to the origin <code>(0, 0)</code>.</p>
11+
12+
<p>(Here, the distance between two points on a plane is the Euclidean distance.)</p>
13+
14+
<p>You may return the answer in any order.&nbsp; The&nbsp;answer is guaranteed to be unique (except for the order that it is in.)</p>
15+
16+
<p>&nbsp;</p>
17+
18+
<div>
19+
<p><strong>Example 1:</strong></p>
20+
21+
<pre>
22+
<strong>Input: </strong>points = <span id="example-input-1-1">[[1,3],[-2,2]]</span>, K = <span id="example-input-1-2">1</span>
23+
<strong>Output: </strong><span id="example-output-1">[[-2,2]]</span>
24+
<strong>Explanation: </strong>
25+
The distance between (1, 3) and the origin is sqrt(10).
26+
The distance between (-2, 2) and the origin is sqrt(8).
27+
Since sqrt(8) &lt; sqrt(10), (-2, 2) is closer to the origin.
28+
We only want the closest K = 1 points from the origin, so the answer is just [[-2,2]].
29+
</pre>
30+
31+
<div>
32+
<p><strong>Example 2:</strong></p>
33+
34+
<pre>
35+
<strong>Input: </strong>points = <span id="example-input-2-1">[[3,3],[5,-1],[-2,4]]</span>, K = <span id="example-input-2-2">2</span>
36+
<strong>Output: </strong><span id="example-output-2">[[3,3],[-2,4]]</span>
37+
(The answer [[-2,4],[3,3]] would also be accepted.)
38+
</pre>
39+
40+
<p>&nbsp;</p>
41+
42+
<p><strong>Note:</strong></p>
43+
44+
<ol>
45+
<li><code>1 &lt;= K &lt;= points.length &lt;= 10000</code></li>
46+
<li><code>-10000 &lt; points[i][0] &lt; 10000</code></li>
47+
<li><code>-10000 &lt; points[i][1] &lt; 10000</code></li>
48+
</ol>
49+
</div>
50+
</div>
51+
52+
53+
### Related Topics
54+
[[Sort](https://github.com/openset/leetcode/tree/master/tag/sort/README.md)]
55+
[[Math](https://github.com/openset/leetcode/tree/master/tag/math/README.md)]
56+
[[Divide and Conquer](https://github.com/openset/leetcode/tree/master/tag/divide-and-conquer/README.md)]
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author Openset <openset.wang@gmail.com> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
## 976. Largest Perimeter Triangle (Easy)
9+
10+
<p>Given an array <code>A</code> of positive lengths, return the largest perimeter of a triangle with <strong>non-zero area</strong>, formed from 3 of these lengths.</p>
11+
12+
<p>If it is impossible to form any&nbsp;triangle of non-zero area, return <code>0</code>.</p>
13+
14+
<p>&nbsp;</p>
15+
16+
<ol>
17+
</ol>
18+
19+
<div>
20+
<p><strong>Example 1:</strong></p>
21+
22+
<pre>
23+
<strong>Input: </strong><span id="example-input-1-1">[2,1,2]</span>
24+
<strong>Output: </strong><span id="example-output-1">5</span>
25+
</pre>
26+
27+
<div>
28+
<p><strong>Example 2:</strong></p>
29+
30+
<pre>
31+
<strong>Input: </strong><span id="example-input-2-1">[1,2,1]</span>
32+
<strong>Output: </strong><span id="example-output-2">0</span>
33+
</pre>
34+
35+
<div>
36+
<p><strong>Example 3:</strong></p>
37+
38+
<pre>
39+
<strong>Input: </strong><span id="example-input-3-1">[3,2,3,4]</span>
40+
<strong>Output: </strong><span id="example-output-3">10</span>
41+
</pre>
42+
43+
<div>
44+
<p><strong>Example 4:</strong></p>
45+
46+
<pre>
47+
<strong>Input: </strong><span id="example-input-4-1">[3,6,2,3]</span>
48+
<strong>Output: </strong><span id="example-output-4">8</span>
49+
</pre>
50+
51+
<p>&nbsp;</p>
52+
53+
<p><strong>Note:</strong></p>
54+
55+
<ol>
56+
<li><code>3 &lt;= A.length &lt;= 10000</code></li>
57+
<li><code>1 &lt;= A[i] &lt;= 10^6</code></li>
58+
</ol>
59+
</div>
60+
</div>
61+
</div>
62+
</div>
63+
64+
65+
### Related Topics
66+
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]
67+
[[Math](https://github.com/openset/leetcode/tree/master/tag/math/README.md)]

‎problems/odd-even-jump/README.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author Openset <openset.wang@gmail.com> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
## 975. Odd Even Jump (Hard)
9+
10+
<p>You are given an integer array <code>A</code>.&nbsp; From&nbsp;some starting index, you can make a series of jumps.&nbsp; The (1st, 3rd, 5th, ...)&nbsp;jumps in the series are called <em>odd numbered jumps</em>, and the (2nd, 4th, 6th, ...) jumps in the series are called <em>even numbered jumps</em>.</p>
11+
12+
<p>You may from index <code>i</code>&nbsp;jump forward to index <code><font face="monospace">j</font></code>&nbsp;(with <code>i&nbsp;&lt; j</code>) in the following way:</p>
13+
14+
<ul>
15+
<li>During odd numbered jumps (ie. jumps 1, 3, 5, ...), you jump to the index <font face="monospace">j</font>&nbsp;such that <code>A[i] &lt;= A[j]</code> and <code>A[j]</code> is the smallest possible value.&nbsp; If there are multiple such indexes <code><font face="monospace">j</font></code>, you can only jump to the <strong>smallest</strong> such index <code><font face="monospace">j</font></code>.</li>
16+
<li>During even numbered jumps (ie. jumps 2, 4, 6, ...), you jump to the index <font face="monospace">j</font>&nbsp;such that <code>A[i] &gt;= A[j]</code> and <code>A[j]</code> is the largest&nbsp;possible value.&nbsp; If there are multiple such indexes <code><font face="monospace">j</font></code>, you can only jump to the <strong>smallest</strong> such index <code><font face="monospace">j</font></code>.</li>
17+
<li>(It may be the case that for some index <code><font face="monospace">i</font>,</code> there are no legal jumps.)</li>
18+
</ul>
19+
20+
<p>A starting index is <em>good</em> if, starting from that index, you can reach the end of the array (index <code>A.length - 1</code>) by jumping some number of times (possibly 0 or more than once.)</p>
21+
22+
<p>Return the number of good starting indexes.</p>
23+
24+
<p>&nbsp;</p>
25+
26+
<p><strong>Example 1:</strong></p>
27+
28+
<pre>
29+
<strong>Input: </strong><span id="example-input-1-1">[10,13,12,14,15]</span>
30+
<strong>Output: </strong><span id="example-output-1">2</span>
31+
<strong>Explanation: </strong>
32+
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&#39;t jump any more.
33+
From starting index i = 1 and i = 2, we can jump to i = 3, then we can&#39;t jump any more.
34+
From starting index i = 3, we can jump to i = 4, so we&#39;ve reached the end.
35+
From starting index i = 4, we&#39;ve reached the end already.
36+
In total, there are 2 different starting indexes (i = 3, i = 4) where we can reach the end with some number of jumps.
37+
</pre>
38+
39+
<div>
40+
<p><strong>Example 2:</strong></p>
41+
42+
<pre>
43+
<strong>Input: </strong><span id="example-input-2-1">[2,3,1,1,4]</span>
44+
<strong>Output: </strong><span id="example-output-2">3</span>
45+
<strong>Explanation: </strong>
46+
From starting index i = 0, we make jumps to i = 1, i = 2, i = 3:
47+
48+
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].
49+
50+
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.
51+
52+
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].
53+
54+
We can&#39;t jump from i = 3 to i = 4, so the starting index i = 0 is not good.
55+
56+
In a similar manner, we can deduce that:
57+
From starting index i = 1, we jump to i = 4, so we reach the end.
58+
From starting index i = 2, we jump to i = 3, and then we can&#39;t jump anymore.
59+
From starting index i = 3, we jump to i = 4, so we reach the end.
60+
From starting index i = 4, we are already at the end.
61+
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.
62+
</pre>
63+
64+
<div>
65+
<p><strong>Example 3:</strong></p>
66+
67+
<pre>
68+
<strong>Input: </strong><span id="example-input-3-1">[5,1,3,4,2]</span>
69+
<strong>Output: </strong><span id="example-output-3">3</span>
70+
<strong>Explanation: </strong>
71+
We can reach the end from starting indexes 1, 2, and 4.
72+
</pre>
73+
</div>
74+
</div>
75+
76+
<p>&nbsp;</p>
77+
78+
<p><strong>Note:</strong></p>
79+
80+
<ol>
81+
<li><code>1 &lt;= A.length &lt;= 20000</code></li>
82+
<li><code>0 &lt;= A[i] &lt; 100000</code></li>
83+
</ol>
84+
85+
86+
### Related Topics
87+
[[Stack](https://github.com/openset/leetcode/tree/master/tag/stack/README.md)]
88+
[[Dynamic Programming](https://github.com/openset/leetcode/tree/master/tag/dynamic-programming/README.md)]
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author Openset <openset.wang@gmail.com> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
## 974. Subarray Sums Divisible by K (Medium)
9+
10+
<p>Given an array <code>A</code> of integers, return the number of (contiguous, non-empty) subarrays that have a sum divisible by <code>K</code>.</p>
11+
12+
<p>&nbsp;</p>
13+
14+
<div>
15+
<p><strong>Example 1:</strong></p>
16+
17+
<pre>
18+
<strong>Input: </strong>A = <span id="example-input-1-1">[4,5,0,-2,-3,1]</span>, K = <span id="example-input-1-2">5</span>
19+
<strong>Output: </strong><span id="example-output-1">7</span>
20+
<strong>Explanation: </strong>There are 7 subarrays with a sum divisible by K = 5:
21+
[4, 5, 0, -2, -3, 1], [5], [5, 0], [5, 0, -2, -3], [0], [0, -2, -3], [-2, -3]
22+
</pre>
23+
24+
<p>&nbsp;</p>
25+
26+
<p><strong>Note:</strong></p>
27+
28+
<ol>
29+
<li><code>1 &lt;= A.length &lt;= 30000</code></li>
30+
<li><code>-10000 &lt;= A[i] &lt;= 10000</code></li>
31+
<li><code>2 &lt;= K &lt;= 10000</code></li>
32+
</ol>
33+
</div>
34+
35+
36+
### Related Topics
37+
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]

0 commit comments

Comments
(0)

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