Introduction
It is hard level algorithm called count of region sum. I like to spend 30 minutes on this algorithm first before I go out to play some tennis. I like to spend 20 minutes to read the problem and think about solution first.
Here is the problem statement link.
Now it is 6:28 PM. I spent over 20 minutes to think about it. It may be a dynamic programming solution, and then we try to find all ranges ending at index i, dp[i] stands for the number of ranges in the given range.
Find the solution
It is time for me to find the solution. It is hard for me to come out a complete solution.
It is so exciting to learn something new today.
Here is the idea from one of blogs.
O(n * logn)解法:
解法I 树状数组(Fenwick Tree):
上述算法将题目转化为下面的问题:
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.解法II 归并排序(Merge Sort):
No comments:
Post a Comment