-
Notifications
You must be signed in to change notification settings - Fork 93
added tasks 350, 352, 354 #111
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
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.
Please change structure to the blocks.
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.
It may be concrete classes.
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.
It may be SummaryRangesTest
class name
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.
Please remove empty line.
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.
Please remove empty lines.
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.
Please remove empty lines.
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 solution is not very fast
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.
I found better implemetation
public class SummaryRanges { private static class Node { int min; int max; public Node(int min, int max) { this.min = min; this.max = max; } public Node(int val) { min = val; max = val; } } List<Node> list; /** Initialize your data structure here. */ public SummaryRanges() { list = new ArrayList<>(); } public void addNum(int val) { int left = 0; int right = list.size()-1; int index = list.size(); while (left <= right) { int mid = left + (right - left) / 2; Node node = list.get(mid); if (node.min <= val && val <= node.max) { return; } else if (val < node.min) { index = mid; right = mid - 1; } else if (val > node.max) { left = mid + 1; } } list.add(index, new Node(val)); } public int[][] getIntervals() { for (int i = 1; i < list.size(); i++) { Node prev = list.get(i-1); Node curr = list.get(i); if (curr.min == prev.max+1) { prev.max = curr.max; list.remove(i--); } } int len = list.size(); int[][] res = new int[len][2]; for (int i = 0; i < len; i++) { Node node = list.get(i); res[i][0] = node.min; res[i][1] = node.max; } return res; } }
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.
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.
ok
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.
Please remove escapes and replace code block with 4 spaces ident.
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.
We may use four space ident for code blocks.
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.
It looks like two lines. It may be changes with code block.
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.
Please remove empty line.
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.
Please remove empty lines
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.
I usually code spaces like that to be easier to see than just writing a block
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.
The idea to use plugin to format codes. If it allows to remove empty line - remove it.
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.
You may keep comments in solutions.
Trailing comment may be moved to separate line.
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.
like that ?
image
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.
Yes, we may keep comments. We only need to move them, in separate line above.
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.
You may move comment inside if or remove it. The description looks very simple.
Kudos, SonarCloud Quality Gate passed! Quality Gate passed
Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell
LGTM
No description provided.