This file contains hidden or 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
| #include "opencv2/core.hpp" | |
| #include <vector> | |
| template<typename T> | |
| cv::Mat_<T> choleskyDecomposition(const cv::Mat_<T>& A) { | |
| int n = A.rows; | |
| cv::Mat L; | |
| if (typeid(T) == typeid(float)) | |
| L = cv::Mat::zeros(n, n, CV_32F); | |
| else if (typeid(T) == typeid(double)) |
This file contains hidden or 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
| def make_deterministic(seed: int = 0): | |
| """Make results deterministic. If seed == -1, do not make deterministic. | |
| Running your script in a deterministic way might slow it down. | |
| Note that for some packages (eg: sklearn's PCA) this function is not enough. | |
| """ | |
| seed = int(seed) | |
| if seed == -1: | |
| return | |
| random.seed(seed) |
This file contains hidden or 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
| class Solution { | |
| public: | |
| string customSortString(string order, string s) { | |
| map<char, int> sMap; | |
| string result; | |
| for(auto const &c: s) | |
| { | |
| ++sMap[c]; | |
| int i; | |
| for(i = 0; i < order.size(); ++i) |
This file contains hidden or 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
| class Solution: | |
| def compareVersion(self, version1: str, version2: str) -> int: | |
| list1 = version1.split('.') | |
| list2 = version2.split('.') | |
| len1 = len(list1) | |
| len2 = len(list2) | |
| i1 = 0 | |
| i2 = 0 | |
| while i1 < len1 and i2 < len2: | |
| int1 = int(list1[i1]) |
This file contains hidden or 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
| class Solution { | |
| public: | |
| string addBinary(string a, string b) { | |
| bool isComplement = false; | |
| int len_a = a.size(); | |
| int len_b = b.size(); | |
| int len = (len_a >= len_b)? len_a : len_b; | |
| string s(len, '0'); | |
| for(; len >= 0; --len) | |
| { |
This file contains hidden or 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
| class Solution { | |
| public: | |
| int minimumBoxes(vector<int>& apple, vector<int>& capacity) { | |
| int appleNum = 0; | |
| for(auto const &instance: apple) | |
| appleNum += instance; | |
| sort(capacity.begin(), capacity.end(), greater<int>()); | |
| int boxNum = 0; | |
| for(int i = 0; i < capacity.size(); ++i) | |
| { |
This file contains hidden or 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
| /** | |
| * Definition for a binary tree node. | |
| * struct TreeNode { | |
| * int val; | |
| * TreeNode *left; | |
| * TreeNode *right; | |
| * TreeNode() : val(0), left(nullptr), right(nullptr) {} | |
| * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} | |
| * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {} | |
| * }; |
This file contains hidden or 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
| class WordDictionary { | |
| private: | |
| map<char, pair<WordDictionary*, bool>> dictMap; | |
| public: | |
| WordDictionary() { | |
| } | |
| ~WordDictionary() { | |
| for(auto &dict: dictMap) | |
| { | |
| delete dict.second.first; |
This file contains hidden or 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
| class Solution { | |
| public: | |
| bool find132pattern(vector<int>& nums) { | |
| int n = nums.size(); | |
| int i, j, k; | |
| for(i = 0; i < n - 2; ++i) | |
| { | |
| for(j = n - 1; j > 1; --j) | |
| { | |
| if(nums[i] < nums[j]) |
This file contains hidden or 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
| /** | |
| * Definition for singly-linked list. | |
| * struct ListNode { | |
| * int val; | |
| * ListNode *next; | |
| * ListNode() : val(0), next(nullptr) {} | |
| * ListNode(int x) : val(x), next(nullptr) {} | |
| * ListNode(int x, ListNode *next) : val(x), next(next) {} | |
| * }; | |
| */ |
NewerOlder