To clarify , == (equality operator) in JavaScript will convert types when comparing.
For example, return 5 = '5' will return true even though it is comparing a number and a string.
This is because JavaScript will convert them to the same type when comparing.
Using === (strict equality operator) will not convert type so the above example would return false
Your solution is not good. Every good boy just use O(1) memory and O(n) time, you use O(n) memory.
Good work!
good work!
In the example there is a little typo
=
should be==
To clarify ,
==
(equality operator) in JavaScript will convert types when comparing.For example,
return 5 = '5'
will returntrue
even though it is comparing a number and a string.This is because JavaScript will convert them to the same type when comparing.
Using
===
(strict equality operator) will not convert type so the above example would returnfalse
This comment is hidden because it contains spoiler information about the solution
==
is never enough.==
bites.==
is inexplicable bugs waiting to happen.===
is much more predictable and untemperamental.