Skip to content

Commit 78df361

Browse files
committed
2229 solved.
1 parent 9b35627 commit 78df361

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
cmake_minimum_required(VERSION 3.21)
2+
project(cpp_2229)
3+
4+
set(CMAKE_CXX_STANDARD 14)
5+
6+
add_executable(cpp_2229 main.cpp)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/// Source : https://leetcode.com/problems/check-if-an-array-is-consecutive/
2+
/// Author : liuyubobobo
3+
/// Time : 2022-04-08
4+
5+
#include <iostream>
6+
#include <vector>
7+
#include <algorithm>
8+
9+
using namespace std;
10+
11+
12+
/// Sorting
13+
/// Time Complexity: O(nlogn)
14+
/// Space Complexity: O(1)
15+
class Solution {
16+
public:
17+
bool isConsecutive(vector<int>& nums) {
18+
19+
sort(nums.begin(), nums.end());
20+
for(int i = 0; i < nums.size(); i ++)
21+
if(nums[i] != nums[0] + i) return false;
22+
return true;
23+
}
24+
};
25+
26+
27+
int main() {
28+
29+
return 0;
30+
}

readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2030,6 +2030,8 @@ email: [liuyubobobo@gmail.com](mailto:liuyubobobo@gmail.com)
20302030
| 2225 | [Find Players With Zero or One Losses](https://leetcode.com/problems/find-players-with-zero-or-one-losses/) | [] | [C++](2001-2500/2225-Find-Players-With-Zero-or-One-Losses/cpp-2225/) | | |
20312031
| 2226 | [Maximum Candies Allocated to K Children](https://leetcode.com/problems/maximum-candies-allocated-to-k-children/) | [] | [C++](2001-2500/2226-Maximum-Candies-Allocated-to-K-Children/cpp-2226/) | | |
20322032
| 2227 | [Encrypt and Decrypt Strings](https://leetcode.com/problems/encrypt-and-decrypt-strings/) | [] | [C++](2001-2500/2227-Encrypt-and-Decrypt-Strings/cpp-2227/) | | |
2033+
| 2228 | Database Problem: [Link](https://github.com/liuyubobobo/Play-Leetcode-Database/) | - | - | - | - |
2034+
| 2229 | [Check if an Array Is Consecutive](https://leetcode.com/problems/check-if-an-array-is-consecutive/) | [] | [C++](2001-2500/2229-Check-if-an-Array-Is-Consecutive/cpp-2229/) | | |
20332035
| | | | | | |
20342036

20352037
## 力扣中文站比赛

0 commit comments

Comments
 (0)