일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 선형대수
- 프로그래머스
- 온라인석사
- 알고리즘
- LAA
- 코딩테스트
- C++
- 기본
- 개발자
- 딥러닝
- 주정부이민
- 캐나다 영주권
- Deep learning
- leetcode
- Plotting
- mpnp
- 마니토바
- EOI
- 머신러닝
- cpp
- 방송통신대학교
- zeros
- MATLAB
- machine learning
- 매트랩
- 방통대
- LV1
- 조지아텍
- omscs
- 컴퓨터과학과
Archives
- Today
- Total
Krononberg
1630. Arithmetic Subarrays.cpp 본문
class Solution {
public:
vector<bool> checkArithmeticSubarrays(vector<int>& nums, vector<int>& l, vector<int>& r) {
int len = l.size();
vector<int>tmp;
vector<bool>res;
for(int i =0; i<len; i++){
for(int j = l[i]; j<=r[i]; j++){
tmp.push_back(nums[j]);
}
sort(tmp.begin(),tmp.end());
int commondiff = tmp[1]-tmp[0];
int flag =0;
for(int j = 0; j<tmp.size()-1; j++){
if(commondiff!= tmp[j+1]-tmp[j]){
flag =1;
res.push_back(false);
break;
}
}
if (flag ==0) res.push_back(true);
tmp.clear();
}
return res;
}
};
'개발 로그 > 알고리즘' 카테고리의 다른 글
1089. Duplicate Zeros.cpp (0) | 2021.10.06 |
---|---|
1370. Increasing Decreasing String.cpp (0) | 2021.10.06 |
1309. Decrypt String from Alphabet to Integer Mapping.cpp (0) | 2021.10.05 |
1827. Minimum Operations to Make the Array Increasing.cpp (0) | 2021.10.05 |
1863. Sum of All Subset XOR Totals.cpp (0) | 2021.10.04 |