본문 바로가기

분류 전체보기36

283. Move Zeroes 283. Move Zeroes Given an integer array nums, move all 0's to the end of it while maintaining the relative order of the non-zero elements. Note that you must do this in-place without making a copy of the array. Example 1: Input: nums = [0,1,0,3,12] Output: [1,3,12,0,0] Example 2: Input: nums = [0] Output: [0] Constraints: 1 2021. 7. 12.
1299. Replace Elements with Greatest Element on Right Side 1299. Replace Elements with Greatest Element on Right Side Given an array arr, replace every element in that array with the greatest element among the elements to its right, and replace the last element with -1. After doing so, return the array. Example 1: Input: arr = [17,18,5,4,6,1] Output: [18,6,6,6,1,-1] Explanation: - index 0 --> the greatest element to the right of index 0 is index 1 (18)... 2021. 7. 6.
941. Valid Mountain Array 941. Valid Mountain Array Given an array of integers arr, return true if and only if it is a valid mountain array. arr.length >= 3 There exists some i with 0 ... > arr[arr.length - 1] Example 1: Input: arr = [2,1] Output: false Example 2: Input: arr = [3,5,5] Output: false Example 3: Input: arr = [0,3,2,1] Output: true Constraints: 1 2021. 7. 6.
[LeetCode | 알고리즘] 03. Arrays 101 (배열) - Search (검색) 배열 검색 : 배열 요소를 검색하는 데는 다양한 형태를 취할 수 있습니다. 선형 검색 Linear Search 이진 검색 Binary Search 1) 선형 검색 Linear Search : 찾고있는 요소를 찾거나 배열의 끝에 도달할 때까지 계속 요소를 확인합니다. 모든 요소를 ​​하나씩 확인하여 요소를 찾는 이 기술을 선형 검색 알고리즘이라고 합니다. 최악의 경우 선형 검색은 전체 배열을 확인합니다. -> 따라서 선형 검색의 시간 복잡도는 다음과 같습니다. O(N) 2) 이진 검색 Binary Search 배열의 요소가 정렬된 순서라면 이진 검색을 사용할 수 있다. 배열의 중간요소를 반복적으로 보고 찾고 있는 요소가 왼쪽에 있는지 오른쪽에 있는지 결정한다. 작업을 수행할 때마다 검색하는 요소의 수를 절.. 2021. 7. 5.
1346. Check If N and Its Double Exist 1346. Check If N and Its Double Exist Given an array arr of integers, check if there exists two integers N and M such that N is the double of M ( i.e. N = 2 * M). More formally check if there exists two indices i and j such that : i != j 0 2021. 7. 5.
27. Remove Element 27. Remove Element 특정값을 리스트에서 몽땅 제거하고 그 갯수가 몇개인지 리턴하는 문제 * 새로운 배열 할당하는 것은 금지 ! 배열 안에서 수정하기. Given an integer array nums and an integer val, remove all occurrences of val in nums in-place. The relative order of the elements may be changed. Since it is impossible to change the length of the array in some languages, you must instead have the result be placed in the first part of the array nums. Mor.. 2021. 7. 5.