forked from liuyubobobo/Play-Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7feca7b
commit 63430a4
Showing
4 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
1121-Divide-Array-Into-Increasing-Sequences/cpp-1121/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
cmake_minimum_required(VERSION 3.14) | ||
project(D) | ||
|
||
set(CMAKE_CXX_STANDARD 14) | ||
|
||
add_executable(D main2.cpp) |
34 changes: 34 additions & 0 deletions
34
1121-Divide-Array-Into-Increasing-Sequences/cpp-1121/main.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/// Source : https://leetcode.com/problems/divide-array-into-increasing-sequences/ | ||
/// Author : liuyubobobo | ||
/// Time : 2019-07-13 | ||
|
||
#include <iostream> | ||
#include <vector> | ||
#include <unordered_map> | ||
|
||
using namespace std; | ||
|
||
|
||
/// Using HashMap to calculate freq | ||
/// Time Complexity: O(n) | ||
/// Space Complexity: O(1) | ||
class Solution { | ||
public: | ||
bool canDivideIntoSubsequences(vector<int>& nums, int K) { | ||
|
||
unordered_map<int, int> freq; | ||
int count = 0; | ||
for(int e: nums){ | ||
freq[e] ++; | ||
count = max(count, freq[e]); | ||
} | ||
|
||
return nums.size() / count >= K; | ||
} | ||
}; | ||
|
||
|
||
int main() { | ||
|
||
return 0; | ||
} |
34 changes: 34 additions & 0 deletions
34
1121-Divide-Array-Into-Increasing-Sequences/cpp-1121/main2.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/// Source : https://leetcode.com/problems/divide-array-into-increasing-sequences/ | ||
/// Author : liuyubobobo | ||
/// Time : 2019-07-13 | ||
|
||
#include <iostream> | ||
#include <vector> | ||
|
||
using namespace std; | ||
|
||
|
||
/// Split | ||
/// Time Complexity: O(n) | ||
/// Space Complexity: O(1) | ||
class Solution { | ||
public: | ||
bool canDivideIntoSubsequences(vector<int>& nums, int K) { | ||
|
||
int count = 0; | ||
for(int start = 0, i = start + 1; i <= nums.size(); i ++) | ||
if(i == nums.size() || nums[i] != nums[start]){ | ||
count = max(count, i - start); | ||
start = i; | ||
i = start; | ||
} | ||
|
||
return nums.size() >= K * count; | ||
} | ||
}; | ||
|
||
|
||
int main() { | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -765,4 +765,5 @@ email: [[email protected]](mailto:[email protected]) | |
| 1118 | [Number of Days in a Month](https://leetcode.com/problems/number-of-days-in-a-month/) | [无] | [C++](1118-Number-of-Days-in-a-Month/cpp-1118/) | | | | ||
| 1119 | [Remove Vowels from a String](https://leetcode.com/problems/remove-vowels-from-a-string/) | [无] | [C++](1119-Remove-Vowels-from-a-String/cpp-1119/) | | | | ||
| 1120 | [Maximum Average Subtree](https://leetcode.com/problems/maximum-average-subtree/) | [无] | [C++](1120-Maximum-Average-Subtree/cpp-1120/) | | | | ||
| 1121 | [Divide Array Into Increasing Sequences](https://leetcode.com/problems/divide-array-into-increasing-sequences/) | [无] | [C++](1121-Divide-Array-Into-Increasing-Sequences/cpp-1121/) | | | | ||
| | | | | | | |