https://leetcode.com/problems/search-in-rotated-sorted-array/description/
target의 index를 구하는 문제
nums 배열의 크기가 5000이라 for문 하나를 사용해도 문제없이 돌아갔다.
class Solution {
public int search(int[] nums, int target) {
int index = -1;
for(int i = 0; i < nums.length; i++) {
if (nums[i] == target) {
index = i;
break;
}
}
return index;
}
}
'코딩테스트' 카테고리의 다른 글
[programmers][PCCE 기출문제] 10번 / 데이터 분석 (0) | 2024.03.13 |
---|---|
[programmers] 이모티콘 할인행사 (0) | 2024.03.13 |
994. Rotting Oranges (0) | 2024.02.21 |
75. Sort Colors (0) | 2024.02.18 |
268. Missing Number (0) | 2024.02.17 |