Leetcode_Swift icon indicating copy to clipboard operation
Leetcode_Swift copied to clipboard

Awesome Resource! Possible optimization to ThreeSum

Open sigmonky opened this issue 6 years ago • 0 comments

NEVERMIND! fails on [-1,-1,-1]

Would filtering the sorted array like this

var lastVal: Int?
let sortedNums = nums.sorted().filter { (val) in
        if lastVal == nil {
            lastVal = val
            return true
        }
        if lastVal! == val {
            return false
        } else {
            lastVal = val
            return true
        }
    }

allow us to get rid of this?

if ((left - 1 > i) && (sortedNums[left] == sortedNums[left - 1]))

sigmonky avatar Oct 25 '19 21:10 sigmonky