문제를 이해하고 있다면 바로 풀이를 보면 됨
전체 코드로 바로 넘어가도 됨
마음대로 번역해서 오역이 있을 수 있음
다음과 같은 속성을 가진 정수 배열 nums가 주어진다.
n번 반복되는 요소를 반환해라.
#1
Input: nums = [1, 2, 3, 3]
Output: 3
#2
Input: nums = [2, 1, 2, 5, 3, 2]
Output: 2
#3
Input: nums = [5, 1, 5, 2, 5, 3, 5, 4]
Output: 5
class Solution {
public int repeatedNTimes(int[] nums) {
for(int i = 0; i < nums.length - 2; i++){
if(nums[i] == nums[i + 1] || nums[i] == nums[i + 2]){
return nums[i];
}
}
return nums[nums.length - 1];
}
}