Skip to content

Commit 4b5f35d

Browse files
authored
Merge pull request kelvins#64 from heitor582/main
[rust] adiciona extra palindromo
2 parents ddf6459 + c334d46 commit 4b5f35d

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-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 |
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) |
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/rust/palindromo.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
fn main() {
2+
println!("{:?}", palindromo("".to_string()));
3+
println!("{:?}", palindromo("a".to_string()));
4+
println!("{:?}", palindromo("abba".to_string()));
5+
println!("{:?}", palindromo("abbas".to_string()));
6+
println!("{:?}", palindromo("tattarrattat".to_string()));
7+
println!("{:?}", palindromo("Was it a palindrome?".to_string()));
8+
println!("{:?}", palindromo("No lemon, no melon".to_string()));
9+
}
10+
pub fn palindromo(mut word: String) -> bool {
11+
word = word.to_lowercase().split_whitespace().collect::<String>();
12+
let reversed_string: String = word.chars().rev().collect::<String>();
13+
if word.len() <= 1 {
14+
return true;
15+
}
16+
word == reversed_string
17+
}

0 commit comments

Comments
 (0)