TODO:
- Monte Carlo Simulation
- Check solution for LeetCode 224. Basic Calculator
- Get another YubiKey
20261009
I went on a date with my wife at Valley Fair Mall
- work
- bought a Dyson hair dryer
- LeetCode
- 127. Word Ladder
- leverage the constraint with
string.ascii_lowercase,
pattern matching
- 58. Length of Last Word (C++)
#include <algorithm>, std::max(),
backwards, static_cast<int>()
- exercises, calorie log
#include <string>
class Solution {
public:
int lengthOfLastWord(std::string s) {
int i = static_cast<int>(s.size() - 1);
while (0 <= i && s[i] == ' ') { --i; }
int length = 0;
while (0 <= i && s[i] != ' ') {
--i;
++length;
}
return length;
}
};
20261008
My wife passed all 4 exams of CPA! Congratulations! Now I’ll be a
stay-at-home-husband…
- !LeetCode
- bought flowers for my wife
- run, workout, diet log
- work (hard)
20261007
- !customer visit
- work
- LeetCode
- 295. Find Median from Data Stream
- two heaps, sqrt decomposition
20261006
I felt a little envious when someone else in my study group got a job
at a Big Tech company, but on second thought, health is what matters
most, and I have a lovely wife.
- !LeetCode
- work (somewhat hard)
- flight to Orange County
- Where The Clawdads Sing
- walking, diet log
20261005
- !LeetCode
- 224. Basic Calculator
- TLE but managed to write a brute-force solution
- work (somewhat hard)
- exercises, calorie log
- LeetCode
- 127. Word Ladder
- 20. Valid Parentheses (C++)
- …evaluating both operands can occasionally be useful when the
expressions have side effects:…That said, deliberately relying on this
with booleans is fairly uncommon and can make code harder to understand.
If your intention is “I need both operations to happen,” it’s usually
clearer to write them separately:
- 111. Minimum Depth of Binary Tree (code review)
- 112. Path Sum (code review)
20261004
- !LeetCode
- 127. Word Ladder
- understood the pattern matching approach, practiced an approach to
iterate English lowercase
- created a pull request
- Python may reuse (intern/cache) some immutable objects to save
memory, but doing so for every object would add lookup, bookkeeping, and
lifetime-management overhead.
- my wife’s driving practice
- LeetCode
- 342. Power of Four (C++)
- recursion, iteration, bit mask, modulo
- 9. Palindrome Number (C++)
- exercises, diet log
20261003
Today was the most relaxing day I’ve had in a while.
- my wife’s driving practice
- watched a movie with my wife
- exercises
20261002
I ate too much in the last 3 days. will try to go back to the normal
state
Today’s Stretches
- LeetCode
- 127. Word Ladder
- time/space complexity analysis
Daily Reps
- work
- LeetCode
- 208. Implement Trie (Prefix Tree) (code review)
- 342. Power of Four (C++)
- normal for loop, recursion, bit mask, mod
class Solution {
public:
bool isPowerOfFour(int n) {
if (n <= 0) { return false; }
if (n == 1) { return true; }
if (n % 4 != 0) { return false; }
return isPowerOfFour(n / 4);
}
};
20261001
Today’s Stretches
Daily Reps
- work
- highway drive with my wife
- flu shot + COVID booster @Kaiser Permanente
- LeetCode
- 295. Find Median from Data Stream
- two heaps, square root decomposition + tried
math.ceil()
- 231. Power of Two (C++)
- jog & walk with my wife
class Solution {
public:
bool isPowerOfTwo(int n) {
if (n <= 0) { return false; }
while (1 < n) {
if (n % 2 == 1) { return false; }
n = n / 2; // n /= 2;
}
return true;
}
};
class Solution {
public:
bool isPowerOfTwo(int n) {
if (n <= 0) { return false; }
return (n & (n - 1)) == 0;
}
};
class Solution {
public:
bool isPowerOfFour(int n) {
const int MASK = 0x55555555;
if (n <= 0) { return false; }
if ((n & MASK) != n) { return false; }
return (n & (n - 1)) == 0;
}
};
index 202609 202611