일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- mpnp
- 컴퓨터과학과
- 코딩테스트
- MATLAB
- EOI
- 개발자
- machine learning
- 프로그래머스
- 알고리즘
- cpp
- 캐나다 영주권
- 위니펙
- 방통대
- 조지아텍
- leetcode
- Plotting
- LV1
- Deep learning
- 매트랩
- zeros
- 머신러닝
- 선형대수
- 주정부이민
- 기본
- C++
- 딥러닝
- 온라인석사
- 방송통신대학교
- LAA
- omscs
Archives
- Today
- Total
Byte by Byte
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 |