From b6b5dfd2ed1266150fe9a5d76be5c1c74916c844 Mon Sep 17 00:00:00 2001 From: openset Date: Sun, 28 Jul 2019 17:03:58 +0800 Subject: [PATCH] Add: new --- README.md | 4 + problems/armstrong-number/README.md | 33 +++++++ .../README.md | 89 +++++++++++++++++++ problems/largest-unique-number/README.md | 34 +++++++ problems/parallel-courses/README.md | 60 +++++++++++++ problems/reported-posts-ii/README.md | 2 +- tag/graph/README.md | 1 + tag/union-find/README.md | 1 + 8 files changed, 223 insertions(+), 1 deletion(-) create mode 100644 problems/armstrong-number/README.md create mode 100644 problems/connecting-cities-with-minimum-cost/README.md create mode 100644 problems/largest-unique-number/README.md create mode 100644 problems/parallel-courses/README.md diff --git a/README.md b/README.md index 5f1e1dd56..ddbb54a9f 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,10 @@ LeetCode Problems' Solutions | # | Title | Solution | Difficulty | | :-: | - | - | :-: | +| 1136 | [Parallel Courses](https://leetcode.com/problems/parallel-courses "εΉ³θ‘Œθ―Ύη¨‹") πŸ”’ | [Go](https://github.com/openset/leetcode/tree/master/problems/parallel-courses) | Hard | +| 1135 | [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 | +| 1134 | [Armstrong Number](https://leetcode.com/problems/armstrong-number "ι˜Ώε§†ζ–―η‰Ήζœ—ζ•°") πŸ”’ | [Go](https://github.com/openset/leetcode/tree/master/problems/armstrong-number) | Easy | +| 1133 | [Largest Unique Number](https://leetcode.com/problems/largest-unique-number "ζœ€ε€§ε”―δΈ€ζ•°") πŸ”’ | [Go](https://github.com/openset/leetcode/tree/master/problems/largest-unique-number) | Easy | | 1132 | [Reported Posts II](https://leetcode.com/problems/reported-posts-ii) πŸ”’ | [MySQL](https://github.com/openset/leetcode/tree/master/problems/reported-posts-ii) | Medium | | 1131 | [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 | | 1130 | [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 | diff --git a/problems/armstrong-number/README.md b/problems/armstrong-number/README.md new file mode 100644 index 000000000..45f546c81 --- /dev/null +++ b/problems/armstrong-number/README.md @@ -0,0 +1,33 @@ + + + + + + + +[< 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 +
+Hint 1 +Check if the given k-digit number equals the sum of the k-th power of it's digits. +
+ +
+Hint 2 +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 ? +
+ +
+Hint 3 +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. +
diff --git a/problems/connecting-cities-with-minimum-cost/README.md b/problems/connecting-cities-with-minimum-cost/README.md new file mode 100644 index 000000000..c5eba8225 --- /dev/null +++ b/problems/connecting-cities-with-minimum-cost/README.md @@ -0,0 +1,89 @@ + + + + + + + +[< 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) + +

There are N cities numbered from 1 to N.

+ +

You are given connections, where each connections[i] = [city1, city2, cost] represents the cost to connect city1 and city2 together.  (A connection is bidirectional: connecting city1 and city2 is the same as connecting city2 and city1.)

+ +

Return the minimum cost so that for every pair of cities, there exists a path of connections (possibly of length 1) that connects those two cities together.  The cost is the sum of the connection costs used. If the task is impossible, return -1.

+ +

 

+ +

Example 1:

+ +

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

Example 2:

+ +

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

 

+ +

Note:

+ +
    +
  1. 1 <= N <= 10000
  2. +
  3. 1 <= connections.length <= 10000
  4. +
  5. 1 <= connections[i][0], connections[i][1] <= N
  6. +
  7. 0 <= connections[i][2] <= 10^5
  8. +
  9. connections[i][0] != connections[i][1]
  10. +
+ +### 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 +
+Hint 1 +What if we model the cities as a graph? +
+ +
+Hint 2 +Build a graph of cities and find the minimum spanning tree. +
+ +
+Hint 3 +You can use a variation of the Kruskal's algorithm for that. +
+ +
+Hint 4 +Sort the edges by their cost and use a union-find data structure. +
+ +
+Hint 5 +How to check all cities are connected? +
+ +
+Hint 6 +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. +
diff --git a/problems/largest-unique-number/README.md b/problems/largest-unique-number/README.md new file mode 100644 index 000000000..86fdad084 --- /dev/null +++ b/problems/largest-unique-number/README.md @@ -0,0 +1,34 @@ + + + + + + + +[< 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 +
+Hint 1 +Find the number of occurrences of each value. +
+ +
+Hint 2 +Use an array or a hash table to do that. +
+ +
+Hint 3 +Look for the largest value with number of occurrences = 1. +
diff --git a/problems/parallel-courses/README.md b/problems/parallel-courses/README.md new file mode 100644 index 000000000..0df03c71d --- /dev/null +++ b/problems/parallel-courses/README.md @@ -0,0 +1,60 @@ + + + + + + + +[< 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 +
+Hint 1 +Try to think of it as a graph problem. +
+ +
+Hint 2 +When will be impossible to study all the courses? +
+ +
+Hint 3 +What if the directed graph has a cycle? +
+ +
+Hint 4 +If you build a graph using the relations, what would be the graph type? +
+ +
+Hint 5 +So the graph is a directed acyclic graph (DAG). +
+ +
+Hint 6 +Imagine having a long path in the DAG, what can you say about the answer then? +
+ +
+Hint 7 +How to find the longest path in a DAG? +
+ +
+Hint 8 +We can use DP in order to solve this. +
diff --git a/problems/reported-posts-ii/README.md b/problems/reported-posts-ii/README.md index 07b1c61ff..5d4dc5252 100644 --- a/problems/reported-posts-ii/README.md +++ b/problems/reported-posts-ii/README.md @@ -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) diff --git a/tag/graph/README.md b/tag/graph/README.md index 4156bb935..0d9b1ea0c 100644 --- a/tag/graph/README.md +++ b/tag/graph/README.md @@ -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 | diff --git a/tag/union-find/README.md b/tag/union-find/README.md index dc79559af..3dd28c59f 100644 --- a/tag/union-find/README.md +++ b/tag/union-find/README.md @@ -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 |