Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

构造线段树中的一个小 BUG #14

Open
dyq666 opened this issue Mar 24, 2020 · 0 comments
Open

构造线段树中的一个小 BUG #14

dyq666 opened this issue Mar 24, 2020 · 0 comments

Comments

@dyq666
Copy link

dyq666 commented Mar 24, 2020

https://github.com/liuyubobobo/Play-with-Data-Structures/blob/master/09-Segment-Tree/03-Building-Segment-Tree/src/SegmentTree.java#L20-L26

线段树 build 中的递归终止条件少一个 l > r, 当构造函数传入空数组时会使 l > r 导致无限递归. (虽然应该不会有传入空数组的情况, 但感觉还是要加上这个条件比较好)

    private void buildSegmentTree(int treeIndex, int l, int r){
        if(l > r)
            return;
        if(l == r){
            tree[treeIndex] = data[l];
            return;
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant