-
Notifications
You must be signed in to change notification settings - Fork 0
added three new algos #5
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR adds three C++ implementations for LeetCode problems: longest substring without repeating chars, merge intervals, and peak element. However, there are critical issues: missing #include in the first file, incorrect merging logic in the second, and array index out-of-bounds in the third. These need fixing before the code can be approved.
| seen.erase(s[left++]); | ||
| } | ||
| seen.insert(s[right]); | ||
| maxLen = max(maxLen, right - left); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::max is used without including . Add ' #include ' to this file.
| sort(intervals.begin(), intervals.end()); | ||
| vector<vector<int>> merged; | ||
| for (auto interval : intervals) { | ||
| if (merged.empty() || merged.back()[1] < interval[1]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This condition incorrectly handles interval merging; it should check if interval[0] <= merged.back()[1] to decide merging.
| int left = 0, right = nums.size(); | ||
| while (left < right) { | ||
| int mid = left + (right - left) / 2; | ||
| if (nums[mid] > nums[mid + 1]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accessing nums[mid+1] may cause out-of-bounds if mid = nums.size() - 1. Revise the binary search to avoid undefined behavior.
No description provided.