Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Refactor JS - Array & Hash#426

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
aakhtar3 wants to merge1 commit intoneetcode-gh:mainfromaakhtar3:main
Closed

Conversation

aakhtar3
Copy link
Collaborator

No description provided.

Copy link
Collaborator

@Ahmad-A0Ahmad-A0 left a comment

Choose a reason for hiding this comment

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

Adding multiple solutions is being discussed in#189, It's also difficult to decide which refactors make the code easier to understand, even though I am partial to your use of array methods.

I don't know where@neetcode-gh wants to take this.

}
};

return [ -1, -1 ]
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 thinkreturn [-1, -1] is needed since"You may assume that each input would haveexactly one solution" for this problem.

Comment on lines 1 to +7
/**
* @param {number[]} nums
* Time O(N) | Space O(N)
* @return {boolean}
*/
var containsDuplicate = function(nums) {
const numsSet = new Set()
for(const i of nums){
if(numsSet.has(i)){
return true
}
numsSet.add(i)
}
return false
return (new Set(nums)).size !== nums.length
Copy link
Collaborator

Choose a reason for hiding this comment

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

This solution has already been proposed (#371)

Comment on lines 7 to +30
var isAnagram = function(s, t) {
let map = {};
if (s.length !== t.length) return false;

const reOrder = (str) => str
.split('')
.sort((a, b) => a.localeCompare(b))
.join('');

return reOrder(s) === reOrder(t)
};

/**
* @param {string} s
* @param {string} t
* Time O(N) | Space O(N)
* @return {boolean}
*/
var isAnagram = function(s, t, map = new Map()) {
if (s.length !== t.length) return false;

if (s.length !== t.length) {
return false;
}
addCharFrequency(s, map);
return subtractCharFrequency(t, map)

for (let i = 0; i < s.length; i++) {
if (map[s[i]]) {
map[s[i]]++;
} else {
map[s[i]] = 1;
}
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Adding multiple solutions is being discussed here (#189)

@aakhtar3
Copy link
CollaboratorAuthor

Closing for anotherPR

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@Ahmad-A0Ahmad-A0Ahmad-A0 left review comments

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@aakhtar3@Ahmad-A0

[8]ページ先頭

©2009-2025 Movatter.jp