Skip to content

Latest commit

 

History

History
25 lines (19 loc) · 840 Bytes

File metadata and controls

25 lines (19 loc) · 840 Bytes

Leetcode Problems JavaScript

Here you can find the best solutions for leetcode problems in JavaScript.

Usage

Just uncomment console.log() and run file.

// Given a non-empty array of integers nums, every element appears twice except for one. Find that single one.
// You must implement a solution with a linear runtime complexity and use only constant extra space.

const singleNumber = function(nums) {
    return nums.filter((v, i, a) => a.indexOf(v) === a.lastIndexOf(v))[0];
};

// console.log(singleNumber([2, 2, 1]));
// console.log(singleNumber([4,1,2,1,2]));
// console.log(singleNumber([1]));

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. Please make sure to update tests as appropriate.

License

Free to use anywhere