반응형
먼저 정렬해주고,
간격 일정한지 판단.
class Solution {
public:
bool canMakeArithmeticProgression(vector<int>& arr) {
sort(arr.begin(),arr.end());
bool flag = true;
int diff = arr[1]-arr[0];
for(int i = 2;i<arr.size();i++){
if(diff != arr[i]-arr[i-1]){
flag = false;
break;
}
}
return flag;
}
};
반응형
'IT > 알고리즘' 카테고리의 다른 글
26★] Leetcode 1491. Average Salary Excluding the Minimum and Maximum Salary (0) | 2020.07.05 |
---|---|
25★] Leetcode 1496. Path Crossing (0) | 2020.07.05 |
23] Leetcode 728. Self Dividing Numbers (0) | 2020.07.04 |
22] Leetcode 1446. Consecutive Characters (0) | 2020.07.03 |
21] Leetcode 657. Robot Return to Origin (0) | 2020.07.01 |
댓글