Skip to content

Instantly share code, notes, and snippets.

View huynhthaihoa's full-sized avatar

huynhthaihoa

View GitHub Profile
@huynhthaihoa
huynhthaihoa / UnscentedKalmanFilter.cpp
Last active February 13, 2026 02:07
UnscentedKalmanFilter (OpenCV + C++)
#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))
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)
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)
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])
@huynhthaihoa
huynhthaihoa / add-binary
Last active April 13, 2024 04:51
Simulation
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)
{
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)
{
/**
* 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) {}
* };
class WordDictionary {
private:
map<char, pair<WordDictionary*, bool>> dictMap;
public:
WordDictionary() {
}
~WordDictionary() {
for(auto &dict: dictMap)
{
delete dict.second.first;
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])
@huynhthaihoa
huynhthaihoa / add-two-numbers
Last active April 13, 2024 04:46
Linked List
/**
* 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) {}
* };
*/