JavaScript solution using Array.find

  • 2
     * @param {number[]} nums
     * @return {number}
    var singleNonDuplicate = function(nums) {
        return nums.find(n => nums.indexOf(n) === nums.lastIndexOf(n))

    edit: switched out "filter" for "find" since we don't need an array

  • 0

    It is not O(log n), but it is a really good solution.

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.