Created
July 20, 2017 22:31
-
-
Save JuneBuug/13cd297e5d7b3658d03059c9cfe5bb79 to your computer and use it in GitHub Desktop.
ladder.swift
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 findLadder(columns : Int, upperArray : [Int]) -> Int { | |
var changeNum = 0 | |
var changableArray = upperArray | |
for i in 0..<changableArray.count{ | |
for j in (i + 1)..<changableArray.count { | |
if changableArray[i] > changableArray[j]{ | |
var temp = changableArray[i] | |
changableArray[i] = changableArray[j] | |
changableArray[j] = temp | |
print("\(i+1) - \(j+1)") | |
changeNum += 1 | |
} | |
} | |
} | |
return changeNum | |
} | |
print(findLadder(columns: 4, upperArray: [4,1,3,2])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment