Skip to content

Commit 41fa01b

Browse files
authored
feat: add typescript solution to lc problem: No.0633.Sum of Square Numbers (doocs#488)
1 parent d967978 commit 41fa01b

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

solution/0600-0699/0633.Sum of Square Numbers/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,24 @@ class Solution {
102102
}
103103
```
104104

105+
### **TypeScript**
106+
107+
```ts
108+
function judgeSquareSum(c: number): boolean {
109+
let a = 0, b = Math.floor(Math.sqrt(c));
110+
while (a <= b) {
111+
let sum = a ** 2 + b ** 2;
112+
if (sum == c) return true;
113+
if (sum < c) {
114+
++a;
115+
} else {
116+
--b;
117+
}
118+
}
119+
return false;
120+
};
121+
```
122+
105123
### **C++**
106124

107125
```cpp

solution/0600-0699/0633.Sum of Square Numbers/README_EN.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,24 @@ class Solution {
9898
}
9999
```
100100

101+
### **TypeScript**
102+
103+
```ts
104+
function judgeSquareSum(c: number): boolean {
105+
let a = 0, b = Math.floor(Math.sqrt(c));
106+
while (a <= b) {
107+
let sum = a ** 2 + b ** 2;
108+
if (sum == c) return true;
109+
if (sum < c) {
110+
++a;
111+
} else {
112+
--b;
113+
}
114+
}
115+
return false;
116+
};
117+
```
118+
101119
### **C++**
102120

103121
```cpp
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function judgeSquareSum(c: number): boolean {
2+
let a = 0, b = Math.floor(Math.sqrt(c));
3+
while (a <= b) {
4+
let sum = a ** 2 + b ** 2;
5+
if (sum == c) return true;
6+
if (sum < c) {
7+
++a;
8+
} else {
9+
--b;
10+
}
11+
}
12+
return false;
13+
};

0 commit comments

Comments
 (0)