wisdompeak / LeetCode

This repository contains the solutions and explanations to the algorithm problems on LeetCode. Only medium or above are included. All are written in C++/Python and implemented by myself. The problems attempted multiple times are labelled with hyperlinks.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

699 解法1 更新 right+1 边界时,未考虑是否会破坏原 right +1

zhi-zhi-zhi opened this issue · comments

测试数据

测试用例:[[1,1],[2,5],[1,1],[2,5]]
预计输出:[1, 5, 5, 10]
实际输出:[1, 5, 5, 6]

文字描述

map[2] 原为 5,第二个 [1,1] 更新时,会将 map[2] 更新为 1 (原 map[1])
导致 第二个 [2,5] 将 map[2] 更新为 6 = (2 + 5),实际应是 10 = (5 +5)

map 更新过程:

0 0
1 1
2 0
2147483647 0

0 0
1 1
2 5
7 0
2147483647 0

0 0
1 2
2 1
7 0
2147483647 0

0 0
1 2
2 6
7 1
2147483647 0

Thanks for fixing it.