■ Algorithm
-
[알고리즘] #Move Zeroes■ Algorithm 2022. 8. 3. 23:19
문제 출처: https://leetcode.com/problems/move-zeroes/ Move Zeroes - 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 문제 해석 정수형 배열 nums가 주어졌을 때, 0이 아닌 요소들은 상대적인 순서를 유지하면서 모든 0을 배열 끝으로 이동하라. NOTE: 배열을 복사하지말고 그대로 사용해야한다. 풀이 0이 아닌 숫자를 만날 때마다 크기가 1씩 증가하는 nonZero 라는 정수형 변수를 선언한다. nums 배열을 순회하..
-
[알고리즘] Rotate Array■ Algorithm 2022. 8. 2. 23:52
문제 출처: https://leetcode.com/problems/rotate-array/ Rotate 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 문제 해석 배열 하나가 주어졌을 때, 배열안의 요소들을 오른쪽으로 K번씩 이동시켜라. (K는 양수이다) 풀이 k번씩 오른쪽으로 한칸씩 이동한다고 할 때, nums.length 만큼 이동하면 다시 원위치로 돌아오게 된다. 따라서 k % nums.length가 실제 이동 횟수라고 볼 수 있다. 이제 배열..
-
[알고리즘] #Squares of a Sorted Array■ Algorithm 2022. 8. 2. 21:38
문제 출처: https://leetcode.com/problems/squares-of-a-sorted-array/ Squares of a 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 문제 해석 오름차순으로 정렬된 정수형 배열 nums가 주어졌을 때, 각 숫자의 제곱 배열을 오름차순으로 정렬해서 리턴하시오. 풀이 Array.map()과 Math.pow()를 이용해서 주어진 배열을 제곱값으로 변환했다. 그리고나서 sort()를 이용해서 ..
-
[알고리즘] #Search Insert Position■ Algorithm 2022. 8. 1. 22:55
문제 출처: https://leetcode.com/problems/search-insert-position/ Search Insert Position - 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이 배열 안에 있으면 해당 인덱스를 반환한다. 없으면 배열에 target이 들어갈 위치의 index를 리턴하라. 풀이 이 문제도 마찬가지로 중간값과 target을 비교해서 구현..
-
[알고리즘] #First Bad Version■ Algorithm 2022. 8. 1. 20:53
문제 출처: https://leetcode.com/problems/first-bad-version/ First Bad Version - 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 문제 해석 당신은 프로젝트 관리자이고, 현재 신제품 개발팀을 이끌고 있습니다. 안타깝게도 최신버전 제품이 품질검사에 실패했습니다. 각 버전은 이전 버전을 기반으로 하고 있으며, bad 버전 이후의 모든 버전들 또한 bad 입니다. 당신이 n개의 버전 [1,2,...n] 갖고 있고, ..
-
[알고리즘] #Binary Search■ Algorithm 2022. 7. 31. 00:05
출처 : https://leetcode.com/problems/binary-search/ Binary Search - 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 문제 해석 704. 이진탐색 오름차순으로 정렬된 정수형 배열 nums와 정수형 변수 target이 주어졌을 때, nums 배열에서 target 값을 찾는 function을 써라. 만약 배열에 target 값이 존재한다면 인덱스 값을 리턴하고, 없으면 -1을 리턴한다. 제약사항 nums 안에 모든 정수..
-
[알고리즘] #Majority Element■ Algorithm 2019. 7. 18. 17:11
출처 : https://leetcode.com/problems/majority-element/ Majority Element - 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 문제 Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. You may assume that the array is..
-
[알고리즘] #Merge Two Sorted Lists■ Algorithm 2019. 7. 12. 16:57
출처 : https://leetcode.com/problems/merge-two-sorted-lists/ Merge Two Sorted Lists - 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 문제 Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. Examp..