Skip to content

Commit 3c41188

Browse files
[Swift] Palindromo
1 parent 478316c commit 3c41188

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Com o objetivo de alcançar uma abrangência maior e encorajar novas pessoas a c
6868
|-------------------------------------|-------|------|--------|----|------|----|--------|-------|------|
6969
| Lista com 2 Pilhas | C/C++ | Java | [Python](./src/python/lista_com_pilhas.py) | Go | Ruby | JS | Pascal | Swift | Rust |
7070
| Soma de 2 Números | C/C++ | Java | [Python](./src/python/soma_dois_numeros.py) | Go | Ruby | JS | Pascal | Swift | Rust |
71-
| [Palíndromo][49] | [C/C++](./src/c/Palindromo.c) | Java | Python | Go | [Ruby](./src/ruby/Palindromo.rb) | [JS](./src/javascript/Palindromo.js) | Pascal | Swift | [Rust](./src/rust/palindromo.rs) |
71+
| [Palíndromo][49] | [C/C++](./src/c/Palindromo.c) | Java | Python | Go | [Ruby](./src/ruby/Palindromo.rb) | [JS](./src/javascript/Palindromo.js) | Pascal | [Swift](./src/swift/palindromo.swift) | [Rust](./src/rust/palindromo.rs) |
7272
| Lista Ligada Desordenada | C/C++ | Java | [Python](./src/python/lista_encadeada_desordenada.py) | Go | Ruby | JS | Pascal | Swift | Rust |
7373
| [Calculo do PI (Leibniz)][50] | C/C++ | Java | [Python](./src/python/calculate_pi.py) | [Go](./src/go/calculatepi/calculatepi.go) | Ruby | [JS](./src/javascript/calculate_pi.js) | Pascal | Swift | Rust |
7474
| Busca em Labirinto | C/C++ | Java | [Python](./src/python/busca_em_labirinto.py) | Go | Ruby | JS | Pascal | Swift | Rust |

src/swift/palindromo.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// palindromo.swift
3+
//
4+
// Created by Matheus Torres on 14/11/20.
5+
//
6+
7+
import Foundation
8+
9+
func isPalindrome(_ string: String) -> Bool {
10+
let lowercasedString: String = string.lowercased().replacingOccurrences(of: " ", with: "")
11+
var reversedString = ""
12+
13+
var reversedStringArray = Array(lowercasedString)
14+
reversedStringArray.reverse()
15+
for word in reversedStringArray { reversedString += "\(word)" }
16+
17+
return (lowercasedString == reversedString)
18+
}
19+
20+
print(isPalindrome(""))
21+
print(isPalindrome("a"))
22+
print(isPalindrome("abba"))
23+
print(isPalindrome("abbas"))
24+
print(isPalindrome("tattarrattat"))
25+
print(isPalindrome("Was it a palindrome?"))
26+
print(isPalindrome("No lemon, no melon"))
27+

0 commit comments

Comments
 (0)