Skip to content

Instantly share code, notes, and snippets.

View eclipselu's full-sized avatar
🏠
Working from home

Lu Dang eclipselu

🏠
Working from home
  • Kitchener, Ontario
View GitHub Profile
@eclipselu
eclipselu / config
Created January 15, 2024 16:10
Ghostty config
theme = GruvboxDarkHard
font-family = Noto Sans Mono
font-size = 14
font-thicken = false
command = /usr/local/bin/fish
font-feature = -dlig
font-feature = -liga
@eclipselu
eclipselu / largetst_rect_in_hist.cpp
Created September 25, 2016 14:10
Largest Rectangle in Histogram
class Solution {
public:
/**
* @param height: A list of integer
* @return: The area of largest rectangle in the histogram
*/
int largestRectangleArea(vector<int> &height) {
stack<int> heightSt;
stack<int> indexSt; // start index
@eclipselu
eclipselu / lru_cache.cpp
Last active September 23, 2016 06:18
LRU Cache
class Node {
public:
int key;
int val;
Node *prev;
Node *next;
Node (int key, int val, Node *prev = NULL, Node *next = NULL) {
this->key = key;
this->val = val;
@eclipselu
eclipselu / evaluate_division.cpp
Created September 18, 2016 10:31
Evaluate Division
class ValType {
public:
double val;
string sym;
ValType () {
this->val = 1.0;
this->sym = "";
}
@eclipselu
eclipselu / random_pick_index.cpp
Created September 13, 2016 06:11
Random Pick Index
class Solution {
private:
vector<int> nums;
public:
Solution(vector<int> nums) {
this->nums = nums;
srand(time(NULL));
}
int pick(int target) {
@eclipselu
eclipselu / integer_replacement.cpp
Created September 13, 2016 05:40
Integer Replacement
class Solution {
public:
int integerReplacement(int n) {
return helper(n);
}
private:
int helper(long n) {
if (n == 1)
return 0;
@eclipselu
eclipselu / rotate_function.cpp
Created September 13, 2016 05:34
Rotate Function
class Solution {
public:
int maxRotateFunction(vector<int>& A) {
int len = A.size();
int sum = 0;
int psum = 0;
// sum
for (int i = 0; i < len; ++i) {
sum += A[i];
@eclipselu
eclipselu / longest_substring.cpp
Created September 9, 2016 09:30
Longest Substring with At Least K Repeating Characters
class Solution {
public:
int longestSubstring(string s, int k) {
vector<int> count = getCharCount(s);
for (int i = 0; i < count.size(); ++i) {
char ch = i + 'a';
if (count[i] > 0 && count[i] < k) {
int max_len = INT_MIN;
vector<string> splits = splitString(s, ch);
@eclipselu
eclipselu / decode.cpp
Created September 9, 2016 02:44
Decode String
class Solution {
public:
string decodeString(string s) {
int len = s.length();
if (len == 0)
return s;
stack<int> num_st;
stack<string> sym_st;
@eclipselu
eclipselu / valid_utf8.cpp
Created September 9, 2016 02:41
Valid UTF8
class Solution {
public:
bool validUtf8(vector<int>& data) {
return isValid(data, 0);
}
private:
bool isValid(vector<int> &data, int startIndex) {
if (startIndex == data.size())
return true;