当前位置 : 主页 > 手机开发 > harmonyos >

leetcode-525-Contiguous Array

来源:互联网 收集:自由互联 发布时间:2023-08-26
Error: cannot solve it. Change 0 to -1, so that it become a zero center problem. Assume s[i] = x, and s[j] = x, so that: s[i] + n[i + 1] … + n[j] = s[j] i.e. n[i + 1] + … + n[j] = 0 Also, if s[j] == 0, we can treat it as corner case. Ba


Error:
cannot solve it. Change 0 to -1, so that it become a zero center problem.

Assume s[i] = x, and s[j] = x, so that: s[i] + n[i + 1] … + n[j] =
s[j] i.e. n[i + 1] + … + n[j] = 0

Also, if s[j] == 0, we can treat it as corner case.

Base on that, we build a map to keep track of sum, if that sum appear before or current sum = 0, compare it to our current max.


网友评论