-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bd5e40c
commit 23889c7
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Problem Statement | ||
|
||
// Given an `integer` `x`, return `true` if `x` is a `palindrome`, and `false` `otherwise`. | ||
|
||
// Understand the Problem first... | ||
|
||
// hme aik integer dia gia hy jis ko x se represent kia gia hy. Apne true return krna hy agr x palindrome hy agr nahi tu false return krna hy. | ||
|
||
// Example 1: | ||
// Input: x = 121 | ||
// Output: true | ||
// Explanation: 121 reads as 121 from left to right and from right to left. | ||
|
||
// Example 2: | ||
// Input: x = -121 | ||
// Output: false | ||
// Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome. | ||
|
||
// Example 3: | ||
// Input: x = 10 | ||
// Output: false | ||
// Explanation: Reads 01 from right to left. Therefore it is not a palindrome. | ||
|
||
// Let's assume first example. However it will be applicable to all the previous mentioned examples. | ||
|
||
let num = 121; | ||
|
||
// Solution:- | ||
// Hm ne isko pehle string me convert krna hy then isko split krna hy on the basis of nothing then isko reverse krna hy ta ke compare kre then isko join krna hy on the basis of nothing then isko string se number me convert krne ke liye parseInt ka use krna hy. Isko for loop se bi kr skte hy. Is ke ilawa aur bi tareqee hy jis ke through solve kr ske. | ||
|
||
let isPalindrome = function (x) { | ||
const reversedNumberInStr = x.toString().split("").reverse().join(""); | ||
return parseInt(reversedNumberInStr) === x; | ||
}; | ||
|
||
console.log(isPalindrome(num)); |