본문 바로가기

LeetCode6

[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] 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.
[JS] 1342. Number of Steps to Reduce a Number to Zero 리트코드 easy 난이도는 쉬운 문제가 많다 백준 브론즈 1에서 실버 5 정도도 꽤 있는듯하다 https://leetcode.com/problems/number-of-steps-to-reduce-a-number-to-zero/ Number of Steps to Reduce a Number to Zero - 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} num * @return {number} */ var numberOfSt.. 2022. 11. 18.
[JS] 412. Fizz Buzz 조건문 기본 문제 if 문을 어떻게 사용하냐에 따라 속도나 비용의 효율을 높일 수 있겠다 https://leetcode.com/problems/fizz-buzz/ Fizz Buzz - 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} n * @return {string[]} */ var fizzBuzz = function(n) { const ans = []; for (let i = 1; i 2022. 11. 16.