Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
19
Task/Palindrome-detection/Swift/palindrome-detection-1.swift
Normal file
19
Task/Palindrome-detection/Swift/palindrome-detection-1.swift
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import Foundation
|
||||
|
||||
// Allow for easy character checking
|
||||
extension String {
|
||||
subscript (i: Int) -> String {
|
||||
return String(Array(self)[i])
|
||||
}
|
||||
}
|
||||
|
||||
func isPalindrome(str:String) -> Bool {
|
||||
if (count(str) == 0 || count(str) == 1) {
|
||||
return true
|
||||
}
|
||||
let removeRange = Range<String.Index>(start: advance(str.startIndex, 1), end: advance(str.endIndex, -1))
|
||||
if (str[0] == str[count(str) - 1]) {
|
||||
return isPalindrome(str.substringWithRange(removeRange))
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
func isPal(str: String) -> Bool {
|
||||
let c = str.characters
|
||||
return lazy(c).reverse()
|
||||
.startsWith(c[c.startIndex...advance(c.startIndex, c.count / 2)])
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue