Skip to content

Commit 09da1ec

Browse files
author
openset
committed
Add: new
1 parent 97f969f commit 09da1ec

File tree

6 files changed

+223
-15
lines changed

6 files changed

+223
-15
lines changed

README.md

Lines changed: 18 additions & 14 deletions
Large diffs are not rendered by default.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
[< Previous](https://github.com/openset/leetcode/tree/master/problems/robot-bounded-in-circle "Robot Bounded In Circle")
9+
                
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/partition-array-for-maximum-sum "Partition Array for Maximum Sum")
11+
12+
## 1042. Flower Planting With No Adjacent (Easy)
13+
14+
<p>You have <code>N</code> gardens, labelled <code>1</code> to <code>N</code>.&nbsp; In each garden, you want to plant one of 4 types of flowers.</p>
15+
16+
<p><code>paths[i] = [x, y]</code> describes the existence of a bidirectional path from garden <code>x</code> to garden <code>y</code>.</p>
17+
18+
<p>Also, there is no garden that has more than 3 paths coming into or leaving it.</p>
19+
20+
<p>Your task is to choose a flower type for each garden such that,&nbsp;for any two gardens connected by a path, they have different types of flowers.</p>
21+
22+
<p>Return <strong>any</strong> such a choice as an array <code>answer</code>, where&nbsp;<code>answer[i]</code> is the type of flower&nbsp;planted in the <code>(i+1)</code>-th garden.&nbsp; The flower types are denoted&nbsp;<font face="monospace">1</font>, <font face="monospace">2</font>, <font face="monospace">3</font>, or <font face="monospace">4</font>.&nbsp; It is guaranteed an answer exists.</p>
23+
24+
<p>&nbsp;</p>
25+
26+
<div>
27+
<p><strong>Example 1:</strong></p>
28+
29+
<pre>
30+
<strong>Input: </strong>N = <span id="example-input-1-1">3</span>, paths = <span id="example-input-1-2">[[1,2],[2,3],[3,1]]</span>
31+
<strong>Output: </strong><span id="example-output-1">[1,2,3]</span>
32+
</pre>
33+
34+
<div>
35+
<p><strong>Example 2:</strong></p>
36+
37+
<pre>
38+
<strong>Input: </strong>N = <span id="example-input-2-1">4</span>, paths = <span id="example-input-2-2">[[1,2],[3,4]]</span>
39+
<strong>Output: </strong><span id="example-output-2">[1,2,1,2]</span>
40+
</pre>
41+
42+
<div>
43+
<p><strong>Example 3:</strong></p>
44+
45+
<pre>
46+
<strong>Input: </strong>N = <span id="example-input-3-1">4</span>, paths = <span id="example-input-3-2">[[1,2],[2,3],[3,4],[4,1],[1,3],[2,4]]</span>
47+
<strong>Output: </strong><span id="example-output-3">[1,2,3,4]</span>
48+
</pre>
49+
50+
<p>&nbsp;</p>
51+
52+
<p><strong><span>Note:</span></strong></p>
53+
54+
<ul>
55+
<li><code><span>1 &lt;= N &lt;= 10000</span></code></li>
56+
<li><code><span>0 &lt;= paths.size &lt;= 20000</span></code></li>
57+
<li>No garden has 4 or more paths coming into or leaving it.</li>
58+
<li>It is guaranteed an answer exists.</li>
59+
</ul>
60+
</div>
61+
</div>
62+
</div>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
[< Previous](https://github.com/openset/leetcode/tree/master/problems/partition-array-for-maximum-sum "Partition Array for Maximum Sum")
9+
                
10+
Next >
11+
12+
## 1044. Longest Duplicate Substring (Hard)
13+
14+
<p>Given a string <code>S</code>, consider all <em>duplicated substrings</em>: (contiguous) substrings of S that occur 2 or more times.&nbsp; (The occurrences&nbsp;may overlap.)</p>
15+
16+
<p>Return <strong>any</strong> duplicated&nbsp;substring that has the longest possible length.&nbsp; (If <code>S</code> does not have a duplicated substring, the answer is <code>&quot;&quot;</code>.)</p>
17+
18+
<p>&nbsp;</p>
19+
20+
<p><strong>Example 1:</strong></p>
21+
22+
<pre>
23+
<strong>Input: </strong><span id="example-input-1-1">&quot;banana&quot;</span>
24+
<strong>Output: </strong><span id="example-output-1">&quot;ana&quot;</span>
25+
</pre>
26+
27+
<p><strong>Example 2:</strong></p>
28+
29+
<pre>
30+
<strong>Input: </strong><span id="example-input-2-1">&quot;abcd&quot;</span>
31+
<strong>Output: </strong><span id="example-output-2">&quot;&quot;</span>
32+
</pre>
33+
34+
<p>&nbsp;</p>
35+
36+
<p><strong>Note:</strong></p>
37+
38+
<ol>
39+
<li><code>2 &lt;= S.length &lt;= 10^5</code></li>
40+
<li><code>S</code> consists of lowercase English letters.</li>
41+
</ol>

problems/moving-stones-until-consecutive-ii/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
[< Previous](https://github.com/openset/leetcode/tree/master/problems/minimum-score-triangulation-of-polygon "Minimum Score Triangulation of Polygon")
99

10-
Next >
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/robot-bounded-in-circle "Robot Bounded In Circle")
1111

1212
## 1040. Moving Stones Until Consecutive II (Medium)
1313

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
[< Previous](https://github.com/openset/leetcode/tree/master/problems/flower-planting-with-no-adjacent "Flower Planting With No Adjacent")
9+
                
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/longest-duplicate-substring "Longest Duplicate Substring")
11+
12+
## 1043. Partition Array for Maximum Sum (Medium)
13+
14+
<p>Given an integer array <code>A</code>, you partition the array into (contiguous) subarrays of length at most <code>K</code>.&nbsp; After partitioning, each subarray has their values changed to become the maximum value of that subarray.</p>
15+
16+
<p>Return the largest sum of the given array after partitioning.</p>
17+
18+
<p>&nbsp;</p>
19+
20+
<p><strong>Example 1:</strong></p>
21+
22+
<pre>
23+
<strong>Input: </strong>A = <span id="example-input-1-1">[1,15,7,9,2,5,10]</span>, K = <span id="example-input-1-2">3</span>
24+
<strong>Output: </strong><span id="example-output-1">84
25+
</span><strong>Explanation</strong>: A becomes [15,15,15,9,10,10,10]</pre>
26+
27+
<p>&nbsp;</p>
28+
29+
<p><strong>Note:</strong></p>
30+
31+
<ol>
32+
<li><code>1 &lt;= K &lt;= A.length&nbsp;&lt;= 500</code></li>
33+
<li><code>0 &lt;= A[i] &lt;= 10^6</code></li>
34+
</ol>
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+
[< Previous](https://github.com/openset/leetcode/tree/master/problems/moving-stones-until-consecutive-ii "Moving Stones Until Consecutive II")
9+
                
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/flower-planting-with-no-adjacent "Flower Planting With No Adjacent")
11+
12+
## 1041. Robot Bounded In Circle (Easy)
13+
14+
<p>On an infinite plane, a&nbsp;robot initially stands at <code>(0, 0)</code> and faces north.&nbsp;&nbsp;The robot can receive one of three instructions:</p>
15+
16+
<ul>
17+
<li><code>&quot;G&quot;</code>: go straight 1 unit;</li>
18+
<li><code>&quot;L&quot;</code>: turn 90 degrees to the left;</li>
19+
<li><code>&quot;R&quot;</code>: turn 90 degress to the right.</li>
20+
</ul>
21+
22+
<p>The robot performs the <code>instructions</code> given in order, and repeats them forever.</p>
23+
24+
<p>Return <code>true</code> if and only if there exists a circle in the plane such that the robot never leaves the circle.</p>
25+
26+
<p>&nbsp;</p>
27+
28+
<p><strong>Example 1:</strong></p>
29+
30+
<pre>
31+
<strong>Input: </strong><span id="example-input-1-1">&quot;GGLLGG&quot;</span>
32+
<strong>Output: </strong><span id="example-output-1">true</span>
33+
<strong>Explanation: </strong>
34+
The robot moves from (0,0) to (0,2), turns 180 degrees, and then returns to (0,0).
35+
When repeating these instructions, the robot remains in the circle of radius 2 centered at the origin.
36+
</pre>
37+
38+
<div>
39+
<p><strong>Example 2:</strong></p>
40+
41+
<pre>
42+
<strong>Input: </strong><span id="example-input-2-1">&quot;GG&quot;</span>
43+
<strong>Output: </strong><span id="example-output-2">false</span>
44+
<strong>Explanation: </strong>
45+
The robot moves north indefinetely.
46+
</pre>
47+
48+
<div>
49+
<p><strong>Example 3:</strong></p>
50+
51+
<pre>
52+
<strong>Input: </strong><span id="example-input-3-1">&quot;GL&quot;</span>
53+
<strong>Output: </strong><span id="example-output-3">true</span>
54+
<strong>Explanation: </strong>
55+
The robot moves from (0, 0) -&gt; (0, 1) -&gt; (-1, 1) -&gt; (-1, 0) -&gt; (0, 0) -&gt; ...
56+
</pre>
57+
</div>
58+
59+
<p>&nbsp;</p>
60+
61+
<p><strong>Note:</strong></p>
62+
63+
<ol>
64+
<li><code>1 &lt;= instructions.length &lt;= 100</code></li>
65+
<li><code>instructions[i]</code> is in <code>{&#39;G&#39;, &#39;L&#39;, &#39;R&#39;}</code></li>
66+
</ol>
67+
</div>

0 commit comments

Comments
 (0)