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
f35825f
commit 6ab1807
Showing
30 changed files
with
72 additions
and
800 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
cmake_minimum_required(VERSION 3.5) | ||
cmake_minimum_required(VERSION 3.13) | ||
project(cpp_0077) | ||
|
||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") | ||
set(CMAKE_CXX_STANDARD 14) | ||
|
||
set(SOURCE_FILES main.cpp) | ||
add_executable(cpp_0077 ${SOURCE_FILES}) | ||
add_executable(cpp_0077 main3.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
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
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,57 @@ | ||
/// Source : https://leetcode.com/problems/combinations/description/ | ||
/// Author : liuyubobobo | ||
/// Time : 2019-03-29 | ||
|
||
#include <iostream> | ||
#include <vector> | ||
|
||
using namespace std; | ||
|
||
|
||
/// Using bit mask | ||
/// Time Complexity: O(2^n * n) | ||
/// Space Complexity: O(1) | ||
class Solution { | ||
|
||
public: | ||
vector<vector<int>> combine(int n, int k) { | ||
|
||
vector<vector<int>> res; | ||
|
||
int LIMIT = (1 << n); | ||
for(int i = 0; i < LIMIT; i ++){ | ||
|
||
vector<int> tres = get_vector(i); | ||
if(tres.size() == k) res.push_back(tres); | ||
} | ||
return res; | ||
} | ||
|
||
private: | ||
vector<int> get_vector(int num){ | ||
|
||
vector<int> res; | ||
int i = 1; | ||
while(num){ | ||
if(num % 2) res.push_back(i); | ||
i ++, num /= 2; | ||
} | ||
return res; | ||
} | ||
}; | ||
|
||
|
||
void print_vec(const vector<int>& vec){ | ||
|
||
for(int e: vec) | ||
cout << e << " "; | ||
cout << endl; | ||
} | ||
|
||
int main() { | ||
|
||
vector<vector<int>> res = Solution().combine(4,2); | ||
for( int i = 0 ; i < res.size() ; i ++ ) | ||
print_vec(res[i]); | ||
return 0; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
1013-Pairs-of-Songs-With-Total-Durations-Divisible-by-60/cpp-1013/CMakeLists.txt
This file was deleted.
Oops, something went wrong.
34 changes: 0 additions & 34 deletions
34
1013-Pairs-of-Songs-With-Total-Durations-Divisible-by-60/cpp-1013/main.cpp
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
1014-Capacity-To-Ship-Packages-Within-D-Days/cpp-1014/CMakeLists.txt
This file was deleted.
Oops, something went wrong.
56 changes: 0 additions & 56 deletions
56
1014-Capacity-To-Ship-Packages-Within-D-Days/cpp-1014/main.cpp
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.