Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1485fdc

Browse files
feat: add typescript solution to lc problem: No.2335
No.2335.Minimum Amount of Time to Fill Cups
1 parent 7198831 commit 1485fdc

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

‎solution/2300-2399/2335.Minimum Amount of Time to Fill Cups/README.md‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,13 @@ func fillCups(amount []int) int {
138138
### **TypeScript**
139139

140140
```ts
141-
141+
function fillCups(amount: number[]): number {
142+
amount.sort((a, b) => a - b);
143+
let [a, b, c] = amount;
144+
let diff = (a + b) - c;
145+
if (diff <= 0) return c;
146+
else return Math.floor((diff + 1) / 2) + c;
147+
};
142148
```
143149

144150
### **...**

‎solution/2300-2399/2335.Minimum Amount of Time to Fill Cups/README_EN.md‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,13 @@ func fillCups(amount []int) int {
127127
### **TypeScript**
128128

129129
```ts
130-
130+
function fillCups(amount: number[]): number {
131+
amount.sort((a, b) => a - b);
132+
let [a, b, c] = amount;
133+
let diff = (a + b) - c;
134+
if (diff <= 0) return c;
135+
else return Math.floor((diff + 1) / 2) + c;
136+
};
131137
```
132138

133139
### **...**
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function fillCups(amount: number[]): number {
2+
amount.sort((a, b) => a - b);
3+
let [a, b, c] = amount;
4+
let diff = (a + b) - c;
5+
if (diff <= 0) return c;
6+
else return Math.floor((diff + 1) / 2) + c;
7+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /