Problem: Subarray Sum (LintCode)
思路
subarray 的题目一定要记住经典的 sum 的结构。
如图所示
用一个 HashMap 来存不同的 sum 值(Key),然后 value 是不同的 index
易错点
是从 i + 1 到 j
第一个 index = -1,这样 i + 1 这个 index 才能取到 0
找到一个值立马return
Last updated
subarray 的题目一定要记住经典的 sum 的结构。
如图所示
用一个 HashMap 来存不同的 sum 值(Key),然后 value 是不同的 index
是从 i + 1 到 j
第一个 index = -1,这样 i + 1 这个 index 才能取到 0
找到一个值立马return
Last updated