Skip to content

Commit e8abc91

Browse files
committedMay 30, 2021
feat: add solutions to lc problems: No.1880,1881
1 parent 1c9126f commit e8abc91

File tree

32 files changed

+1885
-2
lines changed

32 files changed

+1885
-2
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# [1874. ](https://leetcode-cn.com/problems/minimize-product-sum-of-two-arrays)
2+
3+
[English Version](/solution/1800-1899/1874.Minimize%20Product%20Sum%20of%20Two%20Arrays/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
None
10+
11+
## 解法
12+
13+
<!-- 这里可写通用的实现逻辑 -->
14+
15+
<!-- tabs:start -->
16+
17+
### **Python3**
18+
19+
<!-- 这里可写当前语言的特殊实现逻辑 -->
20+
21+
```python
22+
23+
```
24+
25+
### **Java**
26+
27+
<!-- 这里可写当前语言的特殊实现逻辑 -->
28+
29+
```java
30+
31+
```
32+
33+
### **...**
34+
35+
```
36+
37+
```
38+
39+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# [1874. Minimize Product Sum of Two Arrays](https://leetcode.com/problems/minimize-product-sum-of-two-arrays)
2+
3+
[中文文档](/solution/1800-1899/1874.Minimize%20Product%20Sum%20of%20Two%20Arrays/README.md)
4+
5+
## Description
6+
7+
<p>The <b>product sum </b>of two equal-length arrays <code>a</code> and <code>b</code> is equal to the sum of <code>a[i] * b[i]</code> for all <code>0 &lt;= i &lt; a.length</code> (<strong>0-indexed</strong>).</p>
8+
9+
<ul>
10+
<li>For example, if <code>a = [1,2,3,4]</code> and <code>b = [5,2,3,1]</code>, the <strong>product sum</strong> would be <code>1*5 + 2*2 + 3*3 + 4*1 = 22</code>.</li>
11+
</ul>
12+
13+
<p>Given two arrays <code>nums1</code> and <code>nums2</code> of length <code>n</code>, return <em>the <strong>minimum product sum</strong> if you are allowed to <strong>rearrange</strong> the <strong>order</strong> of the elements in </em><code>nums1</code>.&nbsp;</p>
14+
15+
<p>&nbsp;</p>
16+
17+
<p><strong>Example 1:</strong></p>
18+
19+
<pre>
20+
21+
<strong>Input:</strong> nums1 = [5,3,4,2], nums2 = [4,2,2,5]
22+
23+
<strong>Output:</strong> 40
24+
25+
<strong>Explanation:</strong>&nbsp;We can rearrange nums1 to become [3,5,4,2]. The product sum of [3,5,4,2] and [4,2,2,5] is 3*4 + 5*2 + 4*2 + 2*5 = 40.
26+
27+
</pre>
28+
29+
<p><strong>Example 2:</strong></p>
30+
31+
<pre>
32+
33+
<strong>Input:</strong> nums1 = [2,1,4,5,7], nums2 = [3,2,4,8,6]
34+
35+
<strong>Output:</strong> 65
36+
37+
<strong>Explanation: </strong>We can rearrange nums1 to become [5,7,4,1,2]. The product sum of [5,7,4,1,2] and [3,2,4,8,6] is 5*3 + 7*2 + 4*4 + 1*8 + 2*6 = 65.
38+
39+
</pre>
40+
41+
<p>&nbsp;</p>
42+
43+
<p><strong>Constraints:</strong></p>
44+
45+
<ul>
46+
<li><code>n == nums1.length == nums2.length</code></li>
47+
<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>
48+
<li><code>1 &lt;= nums1[i], nums2[i] &lt;= 100</code></li>
49+
</ul>
50+
51+
## Solutions
52+
53+
<!-- tabs:start -->
54+
55+
### **Python3**
56+
57+
```python
58+
59+
```
60+
61+
### **Java**
62+
63+
```java
64+
65+
```
66+
67+
### **...**
68+
69+
```
70+
71+
```
72+
73+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# [1875. ](https://leetcode-cn.com/problems/group-employees-of-the-same-salary)
2+
3+
[English Version](/solution/1800-1899/1875.Group%20Employees%20of%20the%20Same%20Salary/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
None
10+
11+
## 解法
12+
13+
<!-- 这里可写通用的实现逻辑 -->
14+
15+
<!-- tabs:start -->
16+
17+
### **SQL**
18+
19+
```sql
20+
21+
```
22+
23+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# [1875. Group Employees of the Same Salary](https://leetcode.com/problems/group-employees-of-the-same-salary)
2+
3+
[中文文档](/solution/1800-1899/1875.Group%20Employees%20of%20the%20Same%20Salary/README.md)
4+
5+
## Description
6+
7+
<p>Table: <code>Employees</code></p>
8+
9+
10+
11+
<pre>
12+
13+
+-------------+---------+
14+
15+
| Column Name | Type |
16+
17+
+-------------+---------+
18+
19+
| employee_id | int |
20+
21+
| name | varchar |
22+
23+
| salary | int |
24+
25+
+-------------+---------+
26+
27+
employee_id is the primary key for this table.
28+
29+
Each row of this table indicates the employee ID, employee name, and salary.
30+
31+
</pre>
32+
33+
34+
35+
<p>&nbsp;</p>
36+
37+
38+
39+
<p>A company wants to divide the employees into teams such that all the members on each team have the <strong>same salary</strong>. The teams should follow these criteria:</p>
40+
41+
42+
43+
<ul>
44+
<li>Each team should consist of <strong>at least two</strong> employees.</li>
45+
<li>All the employees on a team should have the <strong>same salary</strong>.</li>
46+
<li>All the employees of the same salary should be assigned to the same team.</li>
47+
<li>If the salary of an employee is unique, we <strong>do not</strong> assign this employee to any team.</li>
48+
<li>A team&#39;s ID is assigned based on the <strong>rank of the team&#39;s salary</strong> relative to the other teams&#39; salaries, where the team with the <strong>lowest</strong> salary has <code>team_id = 1</code>. Note that the salaries for employees not on a team are <strong>not included</strong> in this ranking.</li>
49+
</ul>
50+
51+
52+
53+
<p>Write an SQL query to get the <code>team_id</code> of each employee that is in a team.</p>
54+
55+
56+
57+
<p>Return the result table ordered by <code>team_id</code> <strong>in ascending order</strong>. In case of a tie, order it by&nbsp;<code>employee_id</code> in <strong>ascending order</strong>.</p>
58+
59+
60+
61+
<p>The query result format is in the following example:</p>
62+
63+
64+
65+
<p>&nbsp;</p>
66+
67+
68+
69+
<pre>
70+
71+
Employees table:
72+
73+
+-------------+---------+--------+
74+
75+
| employee_id | name | salary |
76+
77+
+-------------+---------+--------+
78+
79+
| 2 | Meir | 3000 |
80+
81+
| 3 | Michael | 3000 |
82+
83+
| 7 | Addilyn | 7400 |
84+
85+
| 8 | Juan | 6100 |
86+
87+
| 9 | Kannon | 7400 |
88+
89+
+-------------+---------+--------+
90+
91+
92+
93+
Result table:
94+
95+
+-------------+---------+--------+---------+
96+
97+
| employee_id | name | salary | team_id |
98+
99+
+-------------+---------+--------+---------+
100+
101+
| 2 | Meir | 3000 | 1 |
102+
103+
| 3 | Michael | 3000 | 1 |
104+
105+
| 7 | Addilyn | 7400 | 2 |
106+
107+
| 9 | Kannon | 7400 | 2 |
108+
109+
+-------------+---------+--------+---------+
110+
111+
112+
113+
Meir (employee_id=2) and Michael (employee_id=3) are in the same team because they have the same salary of 3000.
114+
115+
Addilyn (employee_id=7) and Kannon (employee_id=9) are in the same team because they have the same salary of 7400.
116+
117+
Juan (employee_id=8) is not included in any team because their salary of 6100 is unique (i.e. no other employee has the same salary).
118+
119+
The team IDs are assigned as follows (based on salary ranking, lowest first):
120+
121+
- team_id=1: Meir and Michael, salary of 3000
122+
123+
- team_id=2: Addilyn and Kannon, salary of 7400
124+
125+
Juan&#39;s salary of 6100 is not included in the ranking because they are not on a team.</pre>
126+
127+
## Solutions
128+
129+
<!-- tabs:start -->
130+
131+
### **SQL**
132+
133+
```sql
134+
135+
```
136+
137+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# [1876. 长度为三且各字符不同的子字符串](https://leetcode-cn.com/problems/substrings-of-size-three-with-distinct-characters)
2+
3+
[English Version](/solution/1800-1899/1876.Substrings%20of%20Size%20Three%20with%20Distinct%20Characters/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>如果一个字符串不含有任何重复字符,我们称这个字符串为 <strong>好</strong> 字符串。</p>
10+
11+
<p>给你一个字符串 <code>s</code> ,请你返回 <code>s</code> 中长度为 <strong>3</strong> 的 <strong>好子字符串</strong> 的数量。</p>
12+
13+
<p>注意,如果相同的好子字符串出现多次,每一次都应该被记入答案之中。</p>
14+
15+
<p><strong>子字符串</strong> 是一个字符串中连续的字符序列。</p>
16+
17+
<p> </p>
18+
19+
<p><strong>示例 1:</strong></p>
20+
21+
<pre>
22+
<b>输入:</b>s = "xyzzaz"
23+
<b>输出:</b>1
24+
<b>解释:</b>总共有 4 个长度为 3 的子字符串:"xyz","yzz","zza" 和 "zaz" 。
25+
唯一的长度为 3 的好子字符串是 "xyz" 。
26+
</pre>
27+
28+
<p><strong>示例 2:</strong></p>
29+
30+
<pre>
31+
<b>输入:</b>s = "aababcabc"
32+
<b>输出:</b>4
33+
<b>解释:</b>总共有 7 个长度为 3 的子字符串:"aab","aba","bab","abc","bca","cab" 和 "abc" 。
34+
好子字符串包括 "abc","bca","cab" 和 "abc" 。
35+
</pre>
36+
37+
<p> </p>
38+
39+
<p><strong>提示:</strong></p>
40+
41+
<ul>
42+
<li><code>1 <= s.length <= 100</code></li>
43+
<li><code>s</code>​​​​​​ 只包含小写英文字母。</li>
44+
</ul>
45+
46+
47+
## 解法
48+
49+
<!-- 这里可写通用的实现逻辑 -->
50+
51+
<!-- tabs:start -->
52+
53+
### **Python3**
54+
55+
<!-- 这里可写当前语言的特殊实现逻辑 -->
56+
57+
```python
58+
59+
```
60+
61+
### **Java**
62+
63+
<!-- 这里可写当前语言的特殊实现逻辑 -->
64+
65+
```java
66+
67+
```
68+
69+
### **...**
70+
71+
```
72+
73+
```
74+
75+
<!-- tabs:end -->

0 commit comments

Comments
 (0)