Skip to content

Conversation

@jhm9595
Copy link
Owner

@jhm9595 jhm9595 commented Sep 18, 2022

Time Complexity : O(NM)

int rIdx = nums.length - 1;
for(int i = 0; i < nums.length - 2; i++) {
pick = nums[i];
target = 0 - pick; // pick + target = 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need to write 0-pick. -pick is clear enough.

List<Integer> list = new ArrayList<Integer>();
list.add(nums[i]);
list.add(nums[l]);
list.add(nums[r]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider:

new ArrayList<>(Arrays.asList(nums[i], nums[l], nums[r]));

resultAllList.add(list);
if(nums[i] == nums[l] && nums[l] == nums[r]) {
rIdx--;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why the condition is like this. Can you explain your thought of this if-condition?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was also thinking that I thought wrong.
I just solved so many only zeros case by using this.
But i think this is the wrong way.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only 3 zeros case pass this if phrase.
what i thought at first was, if I delete one zero from the main arr, maybe it will reduce finding every case.
Then for this, I would add set that have index of one zero, and if set has that index pass it.
how about this?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the problem is not about the 3 zeroes cases.

What you got was a TLE.

image

You can click "View all" to see the full test case.

You need to think carefully about why your code got TLE.

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

Successfully merging this pull request may close these issues.

3 participants