본문 바로가기

JS66

[JS] 14. Longest Common Prefix 내 풀이는 아래와 같지만, 성능 개선을 위해서는 check 로 쓴 상태를 없애고, 이처럼 문자열을 더하기보다 인덱스를 구해서 splice 로 한번에 얻는 것이 좋다 다음 풀이 시 고려해서 효율적으로 풀어보자 /** * @param {string[]} strs * @return {string} */ var longestCommonPrefix = function (strs) { let splited = strs.map((el) => el.split("")); let first = splited[0]; let ans = ""; for (let i = 0; i < first.length; i++) { let temp = first[i]; let check = true; if (temp === undefined).. 2022. 12. 12.
[JS] 9. Palindrome Number 백준에서 본것같은 팰런드럼 확인 문제 깊은 복사 후 reverse() 로 뒤집어서 각 index 를 비교하면 된다 https://leetcode.com/problems/palindrome-number/ Palindrome Number - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com /** * @param {number} x * @return {boolean} */ var isPalindrome = function (x) { let token = String(x.. 2022. 11. 22.
[JS] 1. Two Sum 리트코드 1번 문제! 쉽지만 천리길도 한걸음이랬다... https://leetcode.com/problems/two-sum/ Two Sum - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com /** * @param {number[]} nums * @param {number} target * @return {number[]} */ var twoSum = function (nums, target) { for (let i = 0; i < nums.length - 1; .. 2022. 11. 22.
[JS] 383. Ransom Note 해시맵을 사용한 문제 처음에는 두 해시맵을 JSON.stringify 로 문자열로 만들어 같은지를 비교하려 하였으나, 객체의 순서가 다를 수 있으므로 그냥 적은 쪽의 문자를 객체에서 하나씩 빼어 해결하였다 체감 난이도 백준 5 https://leetcode.com/problems/ransom-note/ Ransom Note - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com var canConstruct = function (ransomNote, magazine).. 2022. 11. 18.