Skip to content

feat: add typescript solution to lc problem: No.2073 #614

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 16, 2021
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
28 changes: 28 additions & 0 deletions solution/2000-2099/2073.Time Needed to Buy Tickets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,34 @@ class Solution {
}
```

### **TypeScript**

```ts
function timeRequiredToBuy(tickets: number[], k: number): number {
const n = tickets.length;
let target = tickets[k] - 1;
let ans = 0;
// round1
for (let i = 0; i < n; i++) {
let num = tickets[i];
if (num <= target) {
ans += num;
tickets[i] = 0;
} else {
ans += target;
tickets[i] -= target;
}
}

// round2
for (let i = 0; i <= k; i++) {
let num = tickets[i];
ans += (num > 0 ? 1: 0);
}
return ans;
};
```

### **C++**

```cpp
Expand Down
28 changes: 28 additions & 0 deletions solution/2000-2099/2073.Time Needed to Buy Tickets/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,34 @@ class Solution {
}
```

### **TypeScript**

```ts
function timeRequiredToBuy(tickets: number[], k: number): number {
const n = tickets.length;
let target = tickets[k] - 1;
let ans = 0;
// round1
for (let i = 0; i < n; i++) {
let num = tickets[i];
if (num <= target) {
ans += num;
tickets[i] = 0;
} else {
ans += target;
tickets[i] -= target;
}
}

// round2
for (let i = 0; i <= k; i++) {
let num = tickets[i];
ans += (num > 0 ? 1: 0);
}
return ans;
};
```

### **C++**

```cpp
Expand Down
23 changes: 23 additions & 0 deletions solution/2000-2099/2073.Time Needed to Buy Tickets/Solution.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function timeRequiredToBuy(tickets: number[], k: number): number {
const n = tickets.length;
let target = tickets[k] - 1;
let ans = 0;
// round1
for (let i = 0; i < n; i++) {
let num = tickets[i];
if (num <= target) {
ans += num;
tickets[i] = 0;
} else {
ans += target;
tickets[i] -= target;
}
}

// round2
for (let i = 0; i <= k; i++) {
let num = tickets[i];
ans += (num > 0 ? 1: 0);
}
return ans;
};