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

Discussing Sub-optimal Solutions To Puzzles #959

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)
    }
    
}
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