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 580779b

Browse files
committed
Add a question
1 parent 8058956 commit 580779b

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

‎README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,7 @@ const songDecoder = song => {
12911291

12921292
## 40. Valid Parentheses
12931293

1294-
Given a non-empty string `s` containing just the characters `(`, `)`, `{`, `}`, `[` and `]`, determine if the input string is valid. An input string is valid if open brackets are closed by the same type of brackets, and open brackets are closed in the correct order.
1294+
Given a non-empty string `s` containing just the characters `(`, `)`, `{`, `}`, `[`, `]`, determine if the input string is valid. An input string is valid if open brackets are closed by the same type of brackets, and open brackets are closed in the correct order.
12951295

12961296
```js
12971297
const isValid = s => {
@@ -1333,3 +1333,37 @@ const isValid = s => {
13331333
---
13341334

13351335
**[⬆ Back to Top](#javascript-coding-challenges-for-beginners)**
1336+
1337+
## Reverse Integer
1338+
1339+
Given a signed 32-bit integer `x`, return `x` with its digits reversed. If reversing `x` causes the value to go outside the signed 32-bit integer range [-2<sup>31</sup>, 2<sup>31</sup> - 1], then return 0.
1340+
1341+
```js
1342+
const reverse = x => {
1343+
// Your solution
1344+
};
1345+
1346+
console.log(reverse(0)); // 0
1347+
console.log(reverse(120)); // 21
1348+
console.log(reverse(123)); // 321
1349+
console.log(reverse(-123)); // -321
1350+
console.log(reverse(1534236469)); // 0
1351+
```
1352+
1353+
<details><summary>Solution</summary>
1354+
1355+
```js
1356+
const reverse = x => {
1357+
const MAX = Math.pow(2, 31) - 1;
1358+
const MIN = -1 * Math.pow(2, 31);
1359+
let arr = Math.abs(x).toString().split('');
1360+
const reversed = Math.sign(x) * Number(arr.reverse().join(''));
1361+
return reversed < MIN || reversed > MAX ? 0 : reversed;
1362+
};
1363+
```
1364+
1365+
</details>
1366+
1367+
---
1368+
1369+
**[⬆ Back to Top](#javascript-coding-challenges-for-beginners)**

0 commit comments

Comments
(0)

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