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 2767e38

Browse files
feat: add typescript solution to lc problem: No.2048 (doocs#595)
No.2048.Next Greater Numerically Balanced Number
1 parent f77cebc commit 2767e38

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

‎solution/2000-2099/2048.Next Greater Numerically Balanced Number/README.md‎

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

118+
## **TypeScript**
119+
120+
```ts
121+
function nextBeautifulNumber(n: number): number {
122+
for (let ans = n + 1; ; ans++) {
123+
if (isValid(ans)) {
124+
return ans;
125+
}
126+
}
127+
};
128+
129+
function isValid(n: number): boolean {
130+
let record = new Array(10).fill(0);
131+
while (n > 0) {
132+
const idx = n % 10;
133+
record[idx]++;
134+
n = Math.floor(n / 10);
135+
}
136+
for (let i = 0; i < 10; i++) {
137+
if (record[i] && record[i] != i) return false;
138+
}
139+
return true;
140+
}
141+
```
142+
118143
### **C++**
119144

120145
```cpp

‎solution/2000-2099/2048.Next Greater Numerically Balanced Number/README_EN.md‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,31 @@ class Solution {
106106
}
107107
```
108108

109+
### **TypeScript**
110+
111+
```ts
112+
function nextBeautifulNumber(n: number): number {
113+
for (let ans = n + 1; ; ans++) {
114+
if (isValid(ans)) {
115+
return ans;
116+
}
117+
}
118+
};
119+
120+
function isValid(n: number): boolean {
121+
let record = new Array(10).fill(0);
122+
while (n > 0) {
123+
const idx = n % 10;
124+
record[idx]++;
125+
n = Math.floor(n / 10);
126+
}
127+
for (let i = 0; i < 10; i++) {
128+
if (record[i] && record[i] != i) return false;
129+
}
130+
return true;
131+
}
132+
```
133+
109134
### **C++**
110135

111136
```cpp
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
function nextBeautifulNumber(n: number): number {
2+
for (let ans = n + 1; ; ans++) {
3+
if (isValid(ans)) {
4+
return ans;
5+
}
6+
}
7+
};
8+
9+
function isValid(n: number): boolean {
10+
let record = new Array(10).fill(0);
11+
while (n > 0) {
12+
const idx = n % 10;
13+
record[idx]++;
14+
n = Math.floor(n / 10);
15+
}
16+
for (let i = 0; i < 10; i++) {
17+
if (record[i] && record[i] != i) return false;
18+
}
19+
return true;
20+
}

0 commit comments

Comments
(0)

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