본문 바로가기
Coding Test/LeetCode

[LeetCode] (Strings) Lv Easy. Reverse Integer

by song.ift 2023. 1. 16.

https://leetcode.com/explore/interview/card/top-interview-questions-easy/127/strings/880/

 

Explore - LeetCode

LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore.

leetcode.com

 

javascript
닫기
/** * @param {number} x ​* @return {number} ​*/ function t1(x) { ​​​​let result = parseInt(x.toString().split("").reverse().join("")); ​​​​return result < Math.pow(2, 31) - 1 ? result : 0; } function t2(x) { ​​​​let result = x.toString().split(""); ​​​​result.push("-"); ​​​​result.shift(); ​​​​result.reverse(); ​​​​result = parseInt(result.join("")); ​​​​return result > Math.pow(-2, 31) ? result : 0; } var reverse = function (x) { ​​​​if (x === 0) return 0; ​​​​return (x > 0 ? t1 : t2)(x); };

GitHub : https://github.com/developeSHG/Algorithm-LeetCode/tree/main/reverse-integer

 

GitHub - developeSHG/Algorithm-LeetCode: 릿코드 소스코드

릿코드 소스코드. Contribute to developeSHG/Algorithm-LeetCode development by creating an account on GitHub.

github.com

 

댓글