Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Awesome Resource! Possible optimization to ThreeSum #1

Open
sigmonky opened this issue Oct 25, 2019 · 0 comments
Open

Awesome Resource! Possible optimization to ThreeSum #1

sigmonky opened this issue Oct 25, 2019 · 0 comments

Comments

@sigmonky
Copy link

sigmonky commented Oct 25, 2019

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]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant