Skip to content

Commit

Permalink
1121 added.
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyubobobo committed Jul 14, 2019
1 parent 7feca7b commit 63430a4
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 0 deletions.
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 1121-Divide-Array-Into-Increasing-Sequences/cpp-1121/main.cpp
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 1121-Divide-Array-Into-Increasing-Sequences/cpp-1121/main2.cpp
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;
}
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/) | | |
| | | | | | |

0 comments on commit 63430a4

Please sign in to comment.