Skip to content

Discussing Sub-optimal Solutions To Puzzles #959

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
rpstro02 opened this issue Jan 14, 2021 · 0 comments
Open

Discussing Sub-optimal Solutions To Puzzles #959

rpstro02 opened this issue Jan 14, 2021 · 0 comments

Comments

@rpstro02
Copy link

rpstro02 commented Jan 14, 2021

Would a pull request be accepted that discusses sub-optimal solutions to the puzzles? For example, the following solution for the Two-Sum Problem is the most concise (and perhaps one of the most obvious) but has O(n^2) complexity:

for x in 0..<array.count {
    
    let currentNumber = array[x]
    let numberNeeded = target - currentNumber
    if let targetIndex = array.firstIndex(of: numberNeeded) {
        return (x, targetIndex)
    }
    
}
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant