■ Algorithm
-
[알고리즘] #Roman to Integer■ Algorithm 2022. 10. 13. 00:12
문제 출처: 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가 주어졌을 때, 이를 정수로 변환하는 메서드를 만들어야 한다. Symbol Value I 1 V 5 X 10 L 50 C 100 D 500 M 1000 "IV": 4, "IX": 9, "XL": 40, "XC": 90, "CD": 40..
-
[알고리즘] #Palindrome Number■ Algorithm 2022. 10. 12. 20:41
문제 출처: 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 문제 해석 앞으로 읽어도, 뒤에서 읽어도 값이 같은 숫자를 palindrome 숫자라고 한다. 정수 x가 주어졌을 때, x가 palindrome 숫자이면 true를, 아니면 false를 리턴하라. 풀이 방법1) x를 문자열로 바꾸어 reverse()한 값과 x 값을 비교한다. -> ..
-
[알고리즘] #Longest Substring Without Repeating Characters■ Algorithm 2022. 8. 6. 16:30
문제 출처: https://leetcode.com/problems/longest-substring-without-repeating-characters/ Longest Substring Without Repeating Characters - 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가 주어졌을 때, 반복되는 문자가 없는 가장 긴 문자열의 길이를 구하시오. "abcabcbb" -> 3 ("abc") "bbbbb" -> 1 ("b") "pwwk..
-
[알고리즘] #Remove Nth Node From End of List■ Algorithm 2022. 8. 5. 18:23
문제 출처: https://leetcode.com/problems/remove-nth-node-from-end-of-list/ Remove Nth Node From End of List - 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 문제 해석 연결 리스트의 head가 주어졌을 때, 끝에서 n번째 노드를 지운 head를 리턴하라. 풀이 1) 우선 전체 node의 갯수를 알기 위해 노드 전체를 순회하면서 전체 노드의 갯수를 count에 저장한다. 2) 지우려는 ..
-
[알고리즘] #Middle of the Linked List■ Algorithm 2022. 8. 5. 18:06
문제 출처: https://leetcode.com/problems/middle-of-the-linked-list/ Middle of the Linked List - 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 문제 해석 단일 연결 리스트의 head가 주어졌을 때, 중간 노드를 리턴하는 함수를 구현하시오. 중간 노드가 2개인 경우, 두 번째 노드를 리턴하시오. 풀이 주어진 head를 노드 배열로 변경해서 중간값을 구해서 리턴해준다. /** * Definition..
-
[알고리즘] #Reverse Words in a String III■ Algorithm 2022. 8. 5. 17:37
문제 출처: https://leetcode.com/problems/reverse-words-in-a-string-iii/ Reverse Words in a String III - 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가 주어졌을 때, 단어 순서나 공백은 유지한채 단어를 역순으로 리턴하는 함수를 구현하시오. 풀이 이전에 string을 역순으로 구하는 문제를 reverse()가 아닌 다른 방법으로 풀었으니, 이번에는 reverse()를 사..
-
[알고리즘] #Reverse String■ Algorithm 2022. 8. 5. 17:24
문제 출처: https://leetcode.com/problems/reverse-string/ Reverse String - 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가 주어졌을 때, 각 원소를 역순으로 나열하는 function을 구현하시오. 단, O(1) 메모리를 사용하면서 배열만을 가지고 수정해야한다. 풀이 사실 Array.prototype.reverse() 를 쓰면 단 한줄로 끝나버리는 문제이지만, 이 함수가 없다고 ..
-
[알고리즘] #Two Sum II - Input Array Is Sorted■ Algorithm 2022. 8. 5. 17:09
문제 출처: https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/ Two Sum II - Input Array Is Sorted - 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 문제 해석 오름차순으로 정렬된 정수형 배열이 주어졌을 때, 2개의 요소의 합이 target과 같은 index array를 리턴하라. if (numbers[index_1] + numbers[index_2] === target){..