解题思路

Victoria
Jul 11, 2021

有关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之间。

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Victoria
Victoria

Written by Victoria

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

No responses yet

Write a response