Skip to content

Commit 808c76b

Browse files
committed
feat: add solutions to lc problem: No.2160
No.2160.Minimum Sum of Four Digit Number After Splitting Digits
1 parent e8faeee commit 808c76b

File tree

9 files changed

+144
-8
lines changed

9 files changed

+144
-8
lines changed

solution/1100-1199/1189.Maximum Number of Balloons/README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,10 @@
5858
```python
5959
class Solution:
6060
def maxNumberOfBalloons(self, text: str) -> int:
61-
ans = 0
6261
counter = Counter(text)
6362
counter['l'] >>= 1
6463
counter['o'] >>= 1
65-
return min(counter['b'], counter['a'], counter['l'], counter['o'], counter['n'])
64+
return min(counter[c] for c in 'balon')
6665
```
6766

6867
### **Java**

solution/1100-1199/1189.Maximum Number of Balloons/README_EN.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,10 @@
5151
```python
5252
class Solution:
5353
def maxNumberOfBalloons(self, text: str) -> int:
54-
ans = 0
5554
counter = Counter(text)
5655
counter['l'] >>= 1
5756
counter['o'] >>= 1
58-
return min(counter['b'], counter['a'], counter['l'], counter['o'], counter['n'])
57+
return min(counter[c] for c in 'balon')
5958
```
6059

6160
### **Java**
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
class Solution:
22
def maxNumberOfBalloons(self, text: str) -> int:
3-
ans = 0
43
counter = Counter(text)
54
counter['l'] >>= 1
65
counter['o'] >>= 1
7-
return min(counter['b'], counter['a'], counter['l'], counter['o'], counter['n'])
6+
return min(counter[c] for c in 'balon')

solution/2100-2199/2160.Minimum Sum of Four Digit Number After Splitting Digits/README.md

+50-1
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,64 @@
5151
<!-- 这里可写当前语言的特殊实现逻辑 -->
5252

5353
```python
54-
54+
class Solution:
55+
def minimumSum(self, num: int) -> int:
56+
nums = []
57+
while num:
58+
nums.append(num % 10)
59+
num //= 10
60+
nums.sort()
61+
return 10 * (nums[0] + nums[1]) + nums[2] + nums[3]
5562
```
5663

5764
### **Java**
5865

5966
<!-- 这里可写当前语言的特殊实现逻辑 -->
6067

6168
```java
69+
class Solution {
70+
public int minimumSum(int num) {
71+
int[] nums = new int[4];
72+
for (int i = 0; num != 0; ++i) {
73+
nums[i] = num % 10;
74+
num /= 10;
75+
}
76+
Arrays.sort(nums);
77+
return 10 * (nums[0] + nums[1]) + nums[2] + nums[3];
78+
}
79+
}
80+
```
81+
82+
### **C++**
83+
84+
```cpp
85+
class Solution {
86+
public:
87+
int minimumSum(int num) {
88+
vector<int> nums;
89+
while (num)
90+
{
91+
nums.push_back(num % 10);
92+
num /= 10;
93+
}
94+
sort(nums.begin(), nums.end());
95+
return 10 * (nums[0] + nums[1]) + nums[2] + nums[3];
96+
}
97+
};
98+
```
6299
100+
### **Go**
101+
102+
```go
103+
func minimumSum(num int) int {
104+
var nums []int
105+
for num > 0 {
106+
nums = append(nums, num%10)
107+
num /= 10
108+
}
109+
sort.Ints(nums)
110+
return 10*(nums[0]+nums[1]) + nums[2] + nums[3]
111+
}
63112
```
64113

65114
### **TypeScript**

solution/2100-2199/2160.Minimum Sum of Four Digit Number After Splitting Digits/README_EN.md

+50-1
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,62 @@ The minimum sum can be obtained by the pair [4, 9]: 4 + 9 = 13.
4545
### **Python3**
4646

4747
```python
48-
48+
class Solution:
49+
def minimumSum(self, num: int) -> int:
50+
nums = []
51+
while num:
52+
nums.append(num % 10)
53+
num //= 10
54+
nums.sort()
55+
return 10 * (nums[0] + nums[1]) + nums[2] + nums[3]
4956
```
5057

5158
### **Java**
5259

5360
```java
61+
class Solution {
62+
public int minimumSum(int num) {
63+
int[] nums = new int[4];
64+
for (int i = 0; num != 0; ++i) {
65+
nums[i] = num % 10;
66+
num /= 10;
67+
}
68+
Arrays.sort(nums);
69+
return 10 * (nums[0] + nums[1]) + nums[2] + nums[3];
70+
}
71+
}
72+
```
73+
74+
### **C++**
75+
76+
```cpp
77+
class Solution {
78+
public:
79+
int minimumSum(int num) {
80+
vector<int> nums;
81+
while (num)
82+
{
83+
nums.push_back(num % 10);
84+
num /= 10;
85+
}
86+
sort(nums.begin(), nums.end());
87+
return 10 * (nums[0] + nums[1]) + nums[2] + nums[3];
88+
}
89+
};
90+
```
5491
92+
### **Go**
93+
94+
```go
95+
func minimumSum(num int) int {
96+
var nums []int
97+
for num > 0 {
98+
nums = append(nums, num%10)
99+
num /= 10
100+
}
101+
sort.Ints(nums)
102+
return 10*(nums[0]+nums[1]) + nums[2] + nums[3]
103+
}
55104
```
56105

57106
### **TypeScript**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public:
3+
int minimumSum(int num) {
4+
vector<int> nums;
5+
while (num)
6+
{
7+
nums.push_back(num % 10);
8+
num /= 10;
9+
}
10+
sort(nums.begin(), nums.end());
11+
return 10 * (nums[0] + nums[1]) + nums[2] + nums[3];
12+
}
13+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
func minimumSum(num int) int {
2+
var nums []int
3+
for num > 0 {
4+
nums = append(nums, num%10)
5+
num /= 10
6+
}
7+
sort.Ints(nums)
8+
return 10*(nums[0]+nums[1]) + nums[2] + nums[3]
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution {
2+
public int minimumSum(int num) {
3+
int[] nums = new int[4];
4+
for (int i = 0; num != 0; ++i) {
5+
nums[i] = num % 10;
6+
num /= 10;
7+
}
8+
Arrays.sort(nums);
9+
return 10 * (nums[0] + nums[1]) + nums[2] + nums[3];
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Solution:
2+
def minimumSum(self, num: int) -> int:
3+
nums = []
4+
while num:
5+
nums.append(num % 10)
6+
num //= 10
7+
nums.sort()
8+
return 10 * (nums[0] + nums[1]) + nums[2] + nums[3]

0 commit comments

Comments
 (0)