-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpalindrome2.js
More file actions
36 lines (31 loc) ยท 918 Bytes
/
palindrome2.js
File metadata and controls
36 lines (31 loc) ยท 918 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
* @desc problem : ์ ํจํ ํ๋ฌธ ๋ฌธ์ด
* @desc site : Olympiad
* @desc level: 3
* @desc solution : ์์คํค์ฝ๋๋ฅผ ์ด์ฉํ ๋ฌธ์์ด ํ๋
*/
/**
* solution
* @param {string} str : ๋ฌธ์์ด
*/
function solution(str) {
str = str.trim().toLowerCase();
let answer = 'YES';
let validStr = [];
// ๋น๊ต ๊ฐ๋ฅํ ๋ฌธ์์ด๋ก ๋ณํ(๋ฌธ์๋ง ์ถ์ถ)
for (let i = 0; i < str.length; i++) {
const asc = str[i].charCodeAt();
if (asc > 97 && asc < 122) {
validStr.push(str[i]);
}
}
// ๋์์ ๋ ๋ฌธ์์ด ๋ฐ๋ณตํ๋ฉด์ ๋์ผํ์ง ๋น๊ต
for (let j = 0; j < Math.floor(validStr.length / 2); j++) {
if (validStr[j] !== validStr[validStr.length - 1 - j]) {
answer = 'NO';
}
}
return answer;
}
const answer = solution('found7, time: study; Yduts; emit, 6Dnuof'); //YES
console.log(answer);