Skip to content

349_Intersection_2_Arr#6

Open
Yorkio wants to merge 1 commit intomasterfrom
reviewW2Pr2
Open

349_Intersection_2_Arr#6
Yorkio wants to merge 1 commit intomasterfrom
reviewW2Pr2

Conversation

@Yorkio
Copy link
Owner

@Yorkio Yorkio commented Oct 26, 2016

No description provided.

Copy link
Collaborator

@andriibugaiov andriibugaiov left a comment

Choose a reason for hiding this comment

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

I wonder if you see some sort of label, saying that I have approved the request? The should be one...otherwise we may reconsider our workflow as it adds confusion and it is a bit annoying to approve the request and then write 'you can merge it'.

Or, I guess, we could stick to this criteria: if after receiving feedback you don't see red label, that means the request is approved. What do you think?

for (int i = 0; i < nums1.size(); ++i) {
exist[nums1[i]] = true;
}
for (int i = 0; i < nums2.size(); ++i) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

You don't really need an index here. Just do - for(int num : nums2) {}

Copy link
Owner Author

Choose a reason for hiding this comment

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

Ok. This will make code more readable.

class Solution {
public:
vector<int> intersection(vector<int>& nums1, vector<int>& nums2) {
//if (nums1.size() > nums2.size()) return intersection(nums2, nums1);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is actually a very good idea :) Not sure why you commented it out.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Because if their actual sizes are different it does not say anuthing about sizes of their unique arrays.
So I thought that this will give us profit only sometimes.

vector<int> intersection(vector<int>& nums1, vector<int>& nums2) {
//if (nums1.size() > nums2.size()) return intersection(nums2, nums1);

// The idea here is to use some hash table data structure (set or map).
Copy link
Collaborator

Choose a reason for hiding this comment

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

unordered_set is preferable. You don't wan't to use stuff that adds complexity and brings no value.

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 also done this with unordered set first.
But with unordered set running time was slightly bigger I guess it is because of bigger hidden constant of operation erase in hset than operator [] in hmap.
https://leetcode.com/submissions/detail/80045924/

@andriibugaiov
Copy link
Collaborator

Don't forget to solve second version of the problem :)
349. Intersection of Two Arrays II

@andriibugaiov
Copy link
Collaborator

You didnt reply on this:

"I wonder if you see some sort of label, saying that I have approved the request? The should be one...otherwise we may reconsider our workflow as it adds confusion and it is a bit annoying to approve the request and then write 'you can merge it'.

Or, I guess, we could stick to this criteria: if after receiving feedback you don't see red label, that means the request is approved. What do you think?"

and this:

"Don't forget to solve second version of the problem :)
349. Intersection of Two Arrays II"

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.

2 participants