aquio
BAN USER
Comments (3)
Reputation 0
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
Recursive solution in Swift with saving the string built so far :
var arr = Array("ABC".characters)
var permutations = [String]()
func computePerm(arr: [Character], prefix: String) {
if arr.count == 0 {
permutations.append(prefix)
} else {
var newPrefix = prefix
for i in (0..<arr.count) {
var newArr = arr
newArr.removeAtIndex(i)
computePerm(newArr, prefix: prefix + String(arr[i]))
}
}
}
computePerm(arr, prefix: "")
print(permutations)
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
Open Chat in New Window
Open Chat in New Window
Building balanced BST from sorted array (Swift):
- aquio July 19, 2016