Created
November 15, 2016 10:36
-
-
Save pi3r0/89acc3ae3ed3d4d47fcf082a0baf73ee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func solutionA(_ A : [[Int]]) -> Int { | |
var saddlePoints = 0; | |
for i in 1..<A.count - 1 { | |
for j in 1..<A[i].count - 1 { | |
let columnTest = [A[i][j-1], A[i][j], A[i][j+1]].sorted {$0 < $1}; | |
let lignTest = [A[i-1][j], A[i][j], A[i+1][j]].sorted {$0 > $1}; | |
if (columnTest.first! == A[i][j] && lignTest.first! == A[i][j]) { | |
print("Got it One \(A[i][j]) \(i) \(j) \n"); | |
saddlePoints += 1 ; | |
} | |
if (columnTest.last! == A[i][j] && lignTest.last! == A[i][j]) { | |
print("Got it Two \(A[i][j]) \(i) \(j) \n"); | |
saddlePoints += 1 ; | |
} | |
} | |
} | |
return saddlePoints; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment