Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ LeetCode Problems' Solutions

| # | Title | Solution | Difficulty |
| :-: | - | - | :-: |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
Expand Down
33 changes: 33 additions & 0 deletions problems/armstrong-number/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
<!--+----------------------------------------------------------------------+-->
<!--|@author Openset <openset.wang@gmail.com> |-->
<!--|@link https://github.com/openset |-->
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](https://github.com/openset/leetcode/tree/master/problems/largest-unique-number "Largest Unique Number")

[Next >](https://github.com/openset/leetcode/tree/master/problems/connecting-cities-with-minimum-cost "Connecting Cities With Minimum Cost")

## 1134. Armstrong Number (Easy)



### Related Topics
[[Math](https://github.com/openset/leetcode/tree/master/tag/math/README.md)]

### Hints
<details>
<summary>Hint 1</summary>
Check if the given k-digit number equals the sum of the k-th power of it's digits.
</details>

<details>
<summary>Hint 2</summary>
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 ?
</details>

<details>
<summary>Hint 3</summary>
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.
</details>
89 changes: 89 additions & 0 deletions problems/connecting-cities-with-minimum-cost/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
<!--+----------------------------------------------------------------------+-->
<!--|@author Openset <openset.wang@gmail.com> |-->
<!--|@link https://github.com/openset |-->
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](https://github.com/openset/leetcode/tree/master/problems/armstrong-number "Armstrong Number")

[Next >](https://github.com/openset/leetcode/tree/master/problems/parallel-courses "Parallel Courses")

## 1135. Connecting Cities With Minimum Cost (Medium)

<p>There are <code>N</code> cities numbered from 1 to <code>N</code>.</p>

<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>

<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>

<p>&nbsp;</p>

<p><strong>Example 1:</strong></p>

<p><img alt="" src="https://assets.leetcode.com/uploads/2019/04/20/1314_ex2.png" style="width: 161px; height: 141px;" /></p>

<pre>
<strong>Input: </strong>N = 3, connections = [[1,2,5],[1,3,6],[2,3,1]]
<strong>Output: </strong>6
<strong>Explanation: </strong>
Choosing any 2 edges will connect all cities so we choose the minimum 2.
</pre>

<p><strong>Example 2:</strong></p>

<p><img alt="" src="https://assets.leetcode.com/uploads/2019/04/20/1314_ex1.png" style="width: 136px; height: 91px;" /></p>

<pre>
<strong>Input: </strong>N = 4, connections = [[1,2,3],[3,4,4]]
<strong>Output: </strong>-1
<strong>Explanation: </strong>
There is no way to connect all cities even if all edges are used.
</pre>

<p>&nbsp;</p>

<p><strong>Note:</strong></p>

<ol>
<li><code>1 &lt;= N &lt;= 10000</code></li>
<li><code>1 &lt;= connections.length &lt;= 10000</code></li>
<li><code>1 &lt;= connections[i][0], connections[i][1] &lt;= N</code></li>
<li><code>0 &lt;= connections[i][2] &lt;= 10^5</code></li>
<li><code>connections[i][0] != connections[i][1]</code></li>
</ol>

### Related Topics
[[Union Find](https://github.com/openset/leetcode/tree/master/tag/union-find/README.md)]
[[Graph](https://github.com/openset/leetcode/tree/master/tag/graph/README.md)]

### Hints
<details>
<summary>Hint 1</summary>
What if we model the cities as a graph?
</details>

<details>
<summary>Hint 2</summary>
Build a graph of cities and find the minimum spanning tree.
</details>

<details>
<summary>Hint 3</summary>
You can use a variation of the Kruskal's algorithm for that.
</details>

<details>
<summary>Hint 4</summary>
Sort the edges by their cost and use a union-find data structure.
</details>

<details>
<summary>Hint 5</summary>
How to check all cities are connected?
</details>

<details>
<summary>Hint 6</summary>
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.
</details>
34 changes: 34 additions & 0 deletions problems/largest-unique-number/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
<!--+----------------------------------------------------------------------+-->
<!--|@author Openset <openset.wang@gmail.com> |-->
<!--|@link https://github.com/openset |-->
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](https://github.com/openset/leetcode/tree/master/problems/reported-posts-ii "Reported Posts II")

[Next >](https://github.com/openset/leetcode/tree/master/problems/armstrong-number "Armstrong Number")

## 1133. Largest Unique Number (Easy)



### Related Topics
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]
[[Hash Table](https://github.com/openset/leetcode/tree/master/tag/hash-table/README.md)]

### Hints
<details>
<summary>Hint 1</summary>
Find the number of occurrences of each value.
</details>

<details>
<summary>Hint 2</summary>
Use an array or a hash table to do that.
</details>

<details>
<summary>Hint 3</summary>
Look for the largest value with number of occurrences = 1.
</details>
60 changes: 60 additions & 0 deletions problems/parallel-courses/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
<!--+----------------------------------------------------------------------+-->
<!--|@author Openset <openset.wang@gmail.com> |-->
<!--|@link https://github.com/openset |-->
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](https://github.com/openset/leetcode/tree/master/problems/connecting-cities-with-minimum-cost "Connecting Cities With Minimum Cost")

Next >

## 1136. Parallel Courses (Hard)



### Related Topics
[[Dynamic Programming](https://github.com/openset/leetcode/tree/master/tag/dynamic-programming/README.md)]
[[Depth-first Search](https://github.com/openset/leetcode/tree/master/tag/depth-first-search/README.md)]
[[Graph](https://github.com/openset/leetcode/tree/master/tag/graph/README.md)]

### Hints
<details>
<summary>Hint 1</summary>
Try to think of it as a graph problem.
</details>

<details>
<summary>Hint 2</summary>
When will be impossible to study all the courses?
</details>

<details>
<summary>Hint 3</summary>
What if the directed graph has a cycle?
</details>

<details>
<summary>Hint 4</summary>
If you build a graph using the relations, what would be the graph type?
</details>

<details>
<summary>Hint 5</summary>
So the graph is a directed acyclic graph (DAG).
</details>

<details>
<summary>Hint 6</summary>
Imagine having a long path in the DAG, what can you say about the answer then?
</details>

<details>
<summary>Hint 7</summary>
How to find the longest path in a DAG?
</details>

<details>
<summary>Hint 8</summary>
We can use DP in order to solve this.
</details>
2 changes: 1 addition & 1 deletion problems/reported-posts-ii/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

[< Previous](https://github.com/openset/leetcode/tree/master/problems/maximum-of-absolute-value-expression "Maximum of Absolute Value Expression")

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

## 1132. Reported Posts II (Medium)

Expand Down
1 change: 1 addition & 0 deletions tag/graph/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

| # | 题名 | 标签 | 难度 |
| :-: | - | - | :-: |
| 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 |
| 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 |
| 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 |
| 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 |
Expand Down
1 change: 1 addition & 0 deletions tag/union-find/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

| # | 题名 | 标签 | 难度 |
| :-: | - | - | :-: |
| 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 |
| 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 |
| 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 |
| 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 |
Expand Down