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 21ee77a

Browse files
feat: add typescript solution to lc problem: No.2042、2043
1 parent 1b5b4a7 commit 21ee77a

File tree

6 files changed

+161
-0
lines changed

6 files changed

+161
-0
lines changed

‎solution/2000-2099/2042.Check if Numbers Are Ascending in a Sentence/README.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,23 @@ class Solution {
115115
}
116116
```
117117

118+
### **TypeScript**
119+
120+
```ts
121+
function areNumbersAscending(s: string): boolean {
122+
let strs = s.split(' ');
123+
let prev = Number.MIN_SAFE_INTEGER;
124+
for (let str of strs) {
125+
let num = Number(str)
126+
if (!isNaN(num)) {
127+
if (num <= prev) return false;
128+
prev = num;
129+
}
130+
}
131+
return true;
132+
};
133+
```
134+
118135
### **C++**
119136

120137
```cpp

‎solution/2000-2099/2042.Check if Numbers Are Ascending in a Sentence/README_EN.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,23 @@ class Solution {
101101
}
102102
```
103103

104+
### **TypeScript**
105+
106+
```ts
107+
function areNumbersAscending(s: string): boolean {
108+
let strs = s.split(' ');
109+
let prev = Number.MIN_SAFE_INTEGER;
110+
for (let str of strs) {
111+
let num = Number(str)
112+
if (!isNaN(num)) {
113+
if (num <= prev) return false;
114+
prev = num;
115+
}
116+
}
117+
return true;
118+
};
119+
```
120+
104121
### **C++**
105122

106123
```cpp
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function areNumbersAscending(s: string): boolean {
2+
let strs = s.split(' ');
3+
let prev = Number.MIN_SAFE_INTEGER;
4+
for (let str of strs) {
5+
let num = Number(str)
6+
if (!isNaN(num)) {
7+
if (num <= prev) return false;
8+
prev = num;
9+
}
10+
}
11+
return true;
12+
};

‎solution/2000-2099/2043.Simple Bank System/README.md‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,46 @@ class Bank {
151151
*/
152152
```
153153

154+
### **TypeScript**
155+
156+
```ts
157+
class Bank {
158+
balance: number[];
159+
constructor(balance: number[]) {
160+
this.balance = balance;
161+
}
162+
163+
transfer(account1: number, account2: number, money: number): boolean {
164+
if (account1 > this.balance.length || account2 > this.balance.length || money > this.balance[account1 - 1]) return false;
165+
this.balance[account1 - 1] -= money;
166+
this.balance[account2 - 1] += money;
167+
return true;
168+
}
169+
170+
deposit(account: number, money: number): boolean {
171+
if (account > this.balance.length) return false;
172+
this.balance[account - 1] += money;
173+
return true;
174+
}
175+
176+
withdraw(account: number, money: number): boolean {
177+
if (account > this.balance.length || money > this.balance[account - 1]) {
178+
return false;
179+
}
180+
this.balance[account - 1] -= money;
181+
return true;
182+
}
183+
}
184+
185+
/**
186+
* Your Bank object will be instantiated and called as such:
187+
* var obj = new Bank(balance)
188+
* var param_1 = obj.transfer(account1,account2,money)
189+
* var param_2 = obj.deposit(account,money)
190+
* var param_3 = obj.withdraw(account,money)
191+
*/
192+
```
193+
154194
### **C++**
155195

156196
```cpp

‎solution/2000-2099/2043.Simple Bank System/README_EN.md‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,46 @@ class Bank {
141141
*/
142142
```
143143

144+
### **TypeScript**
145+
146+
```ts
147+
class Bank {
148+
balance: number[];
149+
constructor(balance: number[]) {
150+
this.balance = balance;
151+
}
152+
153+
transfer(account1: number, account2: number, money: number): boolean {
154+
if (account1 > this.balance.length || account2 > this.balance.length || money > this.balance[account1 - 1]) return false;
155+
this.balance[account1 - 1] -= money;
156+
this.balance[account2 - 1] += money;
157+
return true;
158+
}
159+
160+
deposit(account: number, money: number): boolean {
161+
if (account > this.balance.length) return false;
162+
this.balance[account - 1] += money;
163+
return true;
164+
}
165+
166+
withdraw(account: number, money: number): boolean {
167+
if (account > this.balance.length || money > this.balance[account - 1]) {
168+
return false;
169+
}
170+
this.balance[account - 1] -= money;
171+
return true;
172+
}
173+
}
174+
175+
/**
176+
* Your Bank object will be instantiated and called as such:
177+
* var obj = new Bank(balance)
178+
* var param_1 = obj.transfer(account1,account2,money)
179+
* var param_2 = obj.deposit(account,money)
180+
* var param_3 = obj.withdraw(account,money)
181+
*/
182+
```
183+
144184
### **C++**
145185

146186
```cpp
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
class Bank {
2+
balance: number[];
3+
constructor(balance: number[]) {
4+
this.balance = balance;
5+
}
6+
7+
transfer(account1: number, account2: number, money: number): boolean {
8+
if (account1 > this.balance.length || account2 > this.balance.length || money > this.balance[account1 - 1]) return false;
9+
this.balance[account1 - 1] -= money;
10+
this.balance[account2 - 1] += money;
11+
return true;
12+
}
13+
14+
deposit(account: number, money: number): boolean {
15+
if (account > this.balance.length) return false;
16+
this.balance[account - 1] += money;
17+
return true;
18+
}
19+
20+
withdraw(account: number, money: number): boolean {
21+
if (account > this.balance.length || money > this.balance[account - 1]) {
22+
return false;
23+
}
24+
this.balance[account - 1] -= money;
25+
return true;
26+
}
27+
}
28+
29+
/**
30+
* Your Bank object will be instantiated and called as such:
31+
* var obj = new Bank(balance)
32+
* var param_1 = obj.transfer(account1,account2,money)
33+
* var param_2 = obj.deposit(account,money)
34+
* var param_3 = obj.withdraw(account,money)
35+
*/

0 commit comments

Comments
(0)

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