LC 224 - Basic Calculator

Approach This problem is not hard but need to consider some special conditions. I found that actually we just need to trace the actual sign after removing the parantheses. For instance, 1-(2-(3+4)) is equal to 1-2+3+4, so we need to buffer the current actual sign when we get the (. In this case, we stack - when getting the first (, and when approaching the second (, we know that it is negative outside, and this is negative so we need to invert the sign inside this parantheses, so stack + inside. And the sign is removed after ) is encountered. ...

January 9, 2026 · 2 min

LC 3798 - Largest Even Number

Approach We just simply check the last char to see if it is 0,2,4,6,8. We remove the character if it is not one of them, the final string then would be the answer. Code class Solution { public: string largestEven(string s) { while(s.size() > 0) { if((s[s.size()-1] - '0') % 2 == 0) break; s.pop_back(); } return s; } };

January 4, 2026 · 1 min

LC 3794 - Reverse String Prefix

Approach This is really simple, just use the reverse() function. Time complexity is O(N), and no extra space complexity. Code class Solution { public: string reversePrefix(string s, int k) { reverse(s.begin(), s.begin()+k); return s; } };

January 3, 2026 · 1 min