Skip to content

Commit b6b5dfd

Browse files
author
openset
committed
Add: new
1 parent 168d399 commit b6b5dfd

File tree

8 files changed

+223
-1
lines changed

8 files changed

+223
-1
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ LeetCode Problems' Solutions
5454

5555
| # | Title | Solution | Difficulty |
5656
| :-: | - | - | :-: |
57+
| <span id="1136">1136</span> | [Parallel Courses](https://leetcode.com/problems/parallel-courses "平行课程") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/parallel-courses) | Hard |
58+
| <span id="1135">1135</span> | [Connecting Cities With Minimum Cost](https://leetcode.com/problems/connecting-cities-with-minimum-cost "最低成本联通所有城市") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/connecting-cities-with-minimum-cost) | Medium |
59+
| <span id="1134">1134</span> | [Armstrong Number](https://leetcode.com/problems/armstrong-number "阿姆斯特朗数") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/armstrong-number) | Easy |
60+
| <span id="1133">1133</span> | [Largest Unique Number](https://leetcode.com/problems/largest-unique-number "最大唯一数") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/largest-unique-number) | Easy |
5761
| <span id="1132">1132</span> | [Reported Posts II](https://leetcode.com/problems/reported-posts-ii) 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/reported-posts-ii) | Medium |
5862
| <span id="1131">1131</span> | [Maximum of Absolute Value Expression](https://leetcode.com/problems/maximum-of-absolute-value-expression "绝对值表达式的最大值") | [Go](https://github.com/openset/leetcode/tree/master/problems/maximum-of-absolute-value-expression) | Medium |
5963
| <span id="1130">1130</span> | [Minimum Cost Tree From Leaf Values](https://leetcode.com/problems/minimum-cost-tree-from-leaf-values "叶值的最小代价生成树") | [Go](https://github.com/openset/leetcode/tree/master/problems/minimum-cost-tree-from-leaf-values) | Medium |

problems/armstrong-number/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author Openset <[email protected]> |-->
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/largest-unique-number "Largest Unique Number")
9+
                
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/connecting-cities-with-minimum-cost "Connecting Cities With Minimum Cost")
11+
12+
## 1134. Armstrong Number (Easy)
13+
14+
15+
16+
### Related Topics
17+
[[Math](https://github.com/openset/leetcode/tree/master/tag/math/README.md)]
18+
19+
### Hints
20+
<details>
21+
<summary>Hint 1</summary>
22+
Check if the given k-digit number equals the sum of the k-th power of it's digits.
23+
</details>
24+
25+
<details>
26+
<summary>Hint 2</summary>
27+
How to compute the sum of the k-th power of the digits of a number ? Can you divide the number into digits using division and modulus operations ?
28+
</details>
29+
30+
<details>
31+
<summary>Hint 3</summary>
32+
You can find the least significant digit of a number by taking it modulus 10. And you can remove it by dividing the number by 10 (integer division). Once you have a digit, you can raise it to the power of k and add it to the sum.
33+
</details>
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author Openset <[email protected]> |-->
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/armstrong-number "Armstrong Number")
9+
                
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/parallel-courses "Parallel Courses")
11+
12+
## 1135. Connecting Cities With Minimum Cost (Medium)
13+
14+
<p>There are <code>N</code> cities numbered from 1 to <code>N</code>.</p>
15+
16+
<p>You are given <code>connections</code>, where each <code>connections[i] = [city1, city2, cost]</code>&nbsp;represents the cost to connect <code>city1</code> and <code>city2</code> together.&nbsp; (A <em>connection</em> is bidirectional: connecting <code>city1</code> and <code>city2</code> is the same as connecting <code>city2</code> and <code>city1</code>.)</p>
17+
18+
<p>Return the minimum cost so that for every pair of cities, there exists a path&nbsp;of connections (possibly of length 1) that connects those two cities together.&nbsp; The cost is the sum of the connection costs used. If the task is impossible, return -1.</p>
19+
20+
<p>&nbsp;</p>
21+
22+
<p><strong>Example 1:</strong></p>
23+
24+
<p><img alt="" src="https://assets.leetcode.com/uploads/2019/04/20/1314_ex2.png" style="width: 161px; height: 141px;" /></p>
25+
26+
<pre>
27+
<strong>Input: </strong>N = 3, connections = [[1,2,5],[1,3,6],[2,3,1]]
28+
<strong>Output: </strong>6
29+
<strong>Explanation: </strong>
30+
Choosing any 2 edges will connect all cities so we choose the minimum 2.
31+
</pre>
32+
33+
<p><strong>Example 2:</strong></p>
34+
35+
<p><img alt="" src="https://assets.leetcode.com/uploads/2019/04/20/1314_ex1.png" style="width: 136px; height: 91px;" /></p>
36+
37+
<pre>
38+
<strong>Input: </strong>N = 4, connections = [[1,2,3],[3,4,4]]
39+
<strong>Output: </strong>-1
40+
<strong>Explanation: </strong>
41+
There is no way to connect all cities even if all edges are used.
42+
</pre>
43+
44+
<p>&nbsp;</p>
45+
46+
<p><strong>Note:</strong></p>
47+
48+
<ol>
49+
<li><code>1 &lt;= N &lt;= 10000</code></li>
50+
<li><code>1 &lt;= connections.length &lt;= 10000</code></li>
51+
<li><code>1 &lt;= connections[i][0], connections[i][1] &lt;= N</code></li>
52+
<li><code>0 &lt;= connections[i][2] &lt;= 10^5</code></li>
53+
<li><code>connections[i][0] != connections[i][1]</code></li>
54+
</ol>
55+
56+
### Related Topics
57+
[[Union Find](https://github.com/openset/leetcode/tree/master/tag/union-find/README.md)]
58+
[[Graph](https://github.com/openset/leetcode/tree/master/tag/graph/README.md)]
59+
60+
### Hints
61+
<details>
62+
<summary>Hint 1</summary>
63+
What if we model the cities as a graph?
64+
</details>
65+
66+
<details>
67+
<summary>Hint 2</summary>
68+
Build a graph of cities and find the minimum spanning tree.
69+
</details>
70+
71+
<details>
72+
<summary>Hint 3</summary>
73+
You can use a variation of the Kruskal's algorithm for that.
74+
</details>
75+
76+
<details>
77+
<summary>Hint 4</summary>
78+
Sort the edges by their cost and use a union-find data structure.
79+
</details>
80+
81+
<details>
82+
<summary>Hint 5</summary>
83+
How to check all cities are connected?
84+
</details>
85+
86+
<details>
87+
<summary>Hint 6</summary>
88+
At the beginning we have n connected components, each time we connect two components the number of connected components is reduced by one. At the end we should end with only a single component otherwise return -1.
89+
</details>
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 <[email protected]> |-->
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/reported-posts-ii "Reported Posts II")
9+
                
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/armstrong-number "Armstrong Number")
11+
12+
## 1133. Largest Unique Number (Easy)
13+
14+
15+
16+
### Related Topics
17+
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]
18+
[[Hash Table](https://github.com/openset/leetcode/tree/master/tag/hash-table/README.md)]
19+
20+
### Hints
21+
<details>
22+
<summary>Hint 1</summary>
23+
Find the number of occurrences of each value.
24+
</details>
25+
26+
<details>
27+
<summary>Hint 2</summary>
28+
Use an array or a hash table to do that.
29+
</details>
30+
31+
<details>
32+
<summary>Hint 3</summary>
33+
Look for the largest value with number of occurrences = 1.
34+
</details>

problems/parallel-courses/README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author Openset <[email protected]> |-->
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/connecting-cities-with-minimum-cost "Connecting Cities With Minimum Cost")
9+
                
10+
Next >
11+
12+
## 1136. Parallel Courses (Hard)
13+
14+
15+
16+
### Related Topics
17+
[[Dynamic Programming](https://github.com/openset/leetcode/tree/master/tag/dynamic-programming/README.md)]
18+
[[Depth-first Search](https://github.com/openset/leetcode/tree/master/tag/depth-first-search/README.md)]
19+
[[Graph](https://github.com/openset/leetcode/tree/master/tag/graph/README.md)]
20+
21+
### Hints
22+
<details>
23+
<summary>Hint 1</summary>
24+
Try to think of it as a graph problem.
25+
</details>
26+
27+
<details>
28+
<summary>Hint 2</summary>
29+
When will be impossible to study all the courses?
30+
</details>
31+
32+
<details>
33+
<summary>Hint 3</summary>
34+
What if the directed graph has a cycle?
35+
</details>
36+
37+
<details>
38+
<summary>Hint 4</summary>
39+
If you build a graph using the relations, what would be the graph type?
40+
</details>
41+
42+
<details>
43+
<summary>Hint 5</summary>
44+
So the graph is a directed acyclic graph (DAG).
45+
</details>
46+
47+
<details>
48+
<summary>Hint 6</summary>
49+
Imagine having a long path in the DAG, what can you say about the answer then?
50+
</details>
51+
52+
<details>
53+
<summary>Hint 7</summary>
54+
How to find the longest path in a DAG?
55+
</details>
56+
57+
<details>
58+
<summary>Hint 8</summary>
59+
We can use DP in order to solve this.
60+
</details>

problems/reported-posts-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/maximum-of-absolute-value-expression "Maximum of Absolute Value Expression")
99

10-
Next >
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/largest-unique-number "Largest Unique Number")
1111

1212
## 1132. Reported Posts II (Medium)
1313

tag/graph/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
| # | 题名 | 标签 | 难度 |
1111
| :-: | - | - | :-: |
12+
| 1135 | [最低成本联通所有城市](https://github.com/openset/leetcode/tree/master/problems/connecting-cities-with-minimum-cost) | [[并查集](https://github.com/openset/leetcode/tree/master/tag/union-find/README.md)] [[](https://github.com/openset/leetcode/tree/master/tag/graph/README.md)] | Medium |
1213
| 1102 | [得分最高的路径](https://github.com/openset/leetcode/tree/master/problems/path-with-maximum-minimum-value) 🔒 | [[深度优先搜索](https://github.com/openset/leetcode/tree/master/tag/depth-first-search/README.md)] [[并查集](https://github.com/openset/leetcode/tree/master/tag/union-find/README.md)] [[](https://github.com/openset/leetcode/tree/master/tag/graph/README.md)] | Medium |
1314
| 1059 | [从始点到终点的所有路径](https://github.com/openset/leetcode/tree/master/problems/all-paths-from-source-lead-to-destination) 🔒 | [[深度优先搜索](https://github.com/openset/leetcode/tree/master/tag/depth-first-search/README.md)] [[](https://github.com/openset/leetcode/tree/master/tag/graph/README.md)] | Medium |
1415
| 1043 | [分隔数组以得到最大和](https://github.com/openset/leetcode/tree/master/problems/partition-array-for-maximum-sum) | [[](https://github.com/openset/leetcode/tree/master/tag/graph/README.md)] | Medium |

tag/union-find/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
| # | 题名 | 标签 | 难度 |
1111
| :-: | - | - | :-: |
12+
| 1135 | [最低成本联通所有城市](https://github.com/openset/leetcode/tree/master/problems/connecting-cities-with-minimum-cost) | [[并查集](https://github.com/openset/leetcode/tree/master/tag/union-find/README.md)] [[](https://github.com/openset/leetcode/tree/master/tag/graph/README.md)] | Medium |
1213
| 1102 | [得分最高的路径](https://github.com/openset/leetcode/tree/master/problems/path-with-maximum-minimum-value) 🔒 | [[深度优先搜索](https://github.com/openset/leetcode/tree/master/tag/depth-first-search/README.md)] [[并查集](https://github.com/openset/leetcode/tree/master/tag/union-find/README.md)] [[](https://github.com/openset/leetcode/tree/master/tag/graph/README.md)] | Medium |
1314
| 1101 | [彼此熟识的最早时间](https://github.com/openset/leetcode/tree/master/problems/the-earliest-moment-when-everyone-become-friends) 🔒 | [[并查集](https://github.com/openset/leetcode/tree/master/tag/union-find/README.md)] | Medium |
1415
| 1061 | [按字典序排列最小的等效字符串](https://github.com/openset/leetcode/tree/master/problems/lexicographically-smallest-equivalent-string) 🔒 | [[深度优先搜索](https://github.com/openset/leetcode/tree/master/tag/depth-first-search/README.md)] [[并查集](https://github.com/openset/leetcode/tree/master/tag/union-find/README.md)] | Medium |

0 commit comments

Comments
 (0)