The recursive solution also ends when we traverse the dth level.
sean46
@sean46
Posts made by sean46

RE: Add One Row In a tree

RE: Minimum Size Subarray Sum
This is picky, but idiomatic C++ uses static_cast<int> instead of C style cast (int) as seen in approach 3.

RE: Explanation of rule 2, which confused me for a long time.
Thanks OP. Leetcode admins, can we make sure problem statements are clear? Vague use of pronouns etc can cause a lot of confusion in problem statements

RE: Really simple and straightforward Java solution
What's the runtime complexity?

RE: Aren't all these solutions posted here O(n^4)?
You could still get O(N^3) with this approach if you use a set to determine whether all k parts are equal

RE: One line C++
As @john700 said, advancing an iterator past end() is undefined behavior. Here is what I did:
string reverseStr(string s, int k) { for (int front = 0; front < s.size(); front += 2 * k) reverse(s.begin() + front, (front + k >= s.size()) ? s.end() : s.begin() + front + k); return s;

RE: Short O(mn) time O(n) space solution
For the complexity analysis, is my reasoning correct?
O(m * n + (open spaces adjacent to a wall))
Since (open spaces adjacent to a wall) will always be < mn, this solution is O(mn).

RE: Longest Line of Consecutive One in a Matrix
Could you add a comment on how the old/prev work to handle the diagonal case?