all category

programmers

[Programmers Level 0] 잘라서 배열로 저장하기 Javascript

문제정보 문제는 다음과 같습니다. 문자열과 정수가 매개변수로 주어지는데 n만큼씩 문자열을 잘라서 배열에 저장시키는 문제입니다. 제 생각엔 substring()을 활용해서 문제를 풀 수 있을 것 같아서 for문과 substring()을 사용해봤습니다. 나의풀이 function solution(my_str, n) { let answer = [] let counter = n for(i=0; i

leetcode

13. Roman to Integer

문제링크 https://leetcode.com/problems/roman-to-integer/ Roman to Integer - 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 문제정보 로마자로 구성된 문자열 s가 매개변수로 주어집니다. 각 로마자에 대응되는 value를 기반으로 로마자를 정수로 변환하여 리턴합니다. 로마자는 큰것에서 작은것 순으로 표기하지만 작은수가 큰수보다 앞에 있는 경우 작은수는 뺄셈으로 작용합니다. ex : IV = 5 - 1 = 4 Sym..

leetcode

500. Keyboard Row

문제링크 https://leetcode.com/problems/keyboard-row/ Keyboard Row - 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 문제정보 요소가 문자열로 이루어진 배열 words가 주어집니다. 각 요소가 키보드 한줄로 칠 수 있는 경우 그 요소를 담은 배열을 리턴해주세요 the first row consists of the characters "qwertyuiop", the second row consists of the char..

leetcode

231. Power of Two

문제링크 https://leetcode.com/problems/power-of-two/ Power of Two - 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 문제정보 정수 n이 매개변수로 주어집니다. n이 만약 2의 거듭제곱수라면 true를 아니라면 false를 반환하세요. var isPowerOfTwo = function(n) { return (Math.log2(n) % 1 === 0); }; Math.log2()는 세퍼레이터를 진수로하고 2를 밑으로하는 ..

programmers

[Programmers Level 0] 한번만 등장한 문자 Javascript

문제정보 저는 문자열 s에서 중복인 문자들을 모두 제거하라는 조건으로 해석했습니다. 예시 "abcabcadc""d" "abdc""abcd" "hello""eho" 나의풀이 function solution(s) { return s .split('') .filter(ele => s.indexOf(ele) == s.lastIndexOf(ele)) .sort() .join('') } 처음엔 set()으로 중복을 제거하려고했는데 중복된 문자는 한개도 남기지않고 없애야해서 filter를 이용했습니다. filter로 중복이 아닌 문자로만 구성되도록 배열을 재구성해줬습니다. 다른사람의 풀이 function solution(s) { let res = []; for (let c of s) if (s.indexOf(c) =..

programmers

[Programmers Level 2] JadenCase 문자열 만들기 Javascript

문제정보 JadenCase를 만드는 문제입니다. 쉽게 해결할 수 있을 것 같았는데 막히는 부분이 있어서 구글링의 도움을 살짝 받았습니다. 예시 sreturn "3people unFollowed me""3people Unfollowed Me" "for the last week""For The Last Week" 맨 처음 실수한 것이 모든 문자열이 소문자로 주어지지않는다는 것을 간과했습니다. 이걸 해결하기위해서 모든 문자열을 일단 lowercase로 만들어줄 필요가 있었습니다. 나의풀이 function solution(s) { return s .split(" ") .map((ele) => ele.charAt(0).toUpperCase() + ele.slice(1,ele.length).toLowerCase()..

leetcode

34. Find First and Last Position of Element in Sorted Array Medium

문제링크 https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/ Find First and Last Position of Element in Sorted Array - 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 문제정보 내림차순으로 정렬된 정수 요소로 이루어진 배열과 정수 target이 매개변수로 주어집니다. 배열에서 target값을 가진 index를 찾을 수..

programmers

[Programmers Level 1] 약수의 개수와 덧셈 Javascript

문제정보 정수 두개가 주어지고 두 정수 사이의 수들의 합을 구하는 문제입니다. 그런데 약수의 개수가 홀수면 -를 해줘야하네요 예시 leftrightresult 131743 242752 나의풀이 function solution(left, right) { let answer = 0 for(i=left ; i

냠냠맨
'분류 전체보기' 카테고리의 글 목록 (51 Page)