Introduction
It is hard level algorithm called word abbreviation. It is the first time I spent time to work on the algorithm. Here is the gist I created for my study.
From January 2015, she started to practice leetcode questions; she trains herself to stay focus, develops "muscle" memory when she practices those questions one by one. 2015年初, Julia开始参与做Leetcode, 开通自己第一个博客. 刷Leet code的题目, 她看了很多的代码, 每个人那学一点, 也开通Github, 发表自己的代码, 尝试写自己的一些体会. She learns from her favorite sports – tennis, 10,000 serves practice builds up good memory for a great serve. Just keep going. Hard work beats talent when talent fails to work hard.
1. 预处理前n项和数组sums 2. 将sums数组离散化(排序+去重)得到数组osums 3. 遍历sums,记sumi = sums[i] 用二分查找得到[sumi - upper, sumi - lower]的离散化下标[left, right] 用树状数组统计范围[left, right]内的元素个数,并累加至最终结果ans 若lower <= sumi <= upper,额外地令ans+1 将sumi的离散化下标记入树状数组
对于数组sums中的每一个元素sumi,统计出现在sumi左侧,并且数值在[sumi - upper, sumi - lower]范围内的元素个数。 这就等价于统计区间和[0, i],[1, i]... [i - 1, i]当中所有落在范围[lower, upper]之内的区间个数。It is so interesting to read the idea how to solve the algorithm in Chinese. I will do some research and see what I can to solve the algorithm.
res list from whichever stack has the top element closer to target.