Arnold

有关peak的、或者3个什么东西的,尝试遍历 the middle index.

DP题目:先想brute force,想想怎么用recursion做,然后想怎么用iteration来做,然后想怎么用caching的方式来optimize。最后想到底几个数字需要被cache?比如如果是fib,其实只有上两个数字需要被cache。

找那种连续多少个连着xxx的subarray的基本上都可以用sliding window来做。具体方法是:先移动右边一直到找到满足的为止,然后开始移动左边,直到不再满足,就又开始移动右边。这种办法一般来说是最time efficient的。O(n)就可以。或者说可以用某种map/array,把结果放在里面然后遍历那个map本身。这种一般来说给的数字range会比较小,类似100 — 10000之间。

--

--

my own solution

Again, the logic that head is not null and head.next is not null so that ans = head.next else return head can be shorten to if head is null or head.next is null then we return head. And then we continue with ans = head.next. this is again a logic problem that can be simplified.

--

--

Arnold

Arnold

"What if I fall?" "Oh my darling, but what if you fly?"