1
1
mirror of https://github.com/theoludwig/programming-challenges.git synced 2024-12-08 00:45:29 +01:00

feat(solutions): add is-palindrome/rust/function

This commit is contained in:
Divlo 2023-01-04 18:28:14 +01:00
parent 257ab19f53
commit e17156f0ab
No known key found for this signature in database
GPG Key ID: 8F9478F220CE65E9
5 changed files with 31 additions and 1 deletions

View File

@ -6,7 +6,7 @@ Created by [@Divlo](https://github.com/Divlo) on 5 July 2020.
The function should return `true` if a given string (case insensitive) is a palindrome and `false` if it's not the case. The function should return `true` if a given string (case insensitive) is a palindrome and `false` if it's not the case.
**Note :** a **Palindrome** is a word, phrase, or sequence that reads the **same backwards as forwards**, e.g. Kayak. **Note:** a **Palindrome** is a word, phrase, or sequence that reads the **same backwards as forwards**, e.g. Kayak.
## Examples ## Examples

View File

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "rust_application"
version = "1.0.0"

View File

@ -0,0 +1,6 @@
[package]
name = "rust_application"
version = "1.0.0"
edition = "2021"
[dependencies]

View File

@ -0,0 +1,3 @@
# is-palindrome/rust/function
Created by [@Divlo](https://github.com/Divlo) on 4 January 2023.

View File

@ -0,0 +1,14 @@
use std::io;
fn main() {
let mut string = String::new();
io::stdin()
.read_line(&mut string)
.expect("Failed to read `stdin` line.");
let string = string.trim().replace(" ", "").to_lowercase();
let mut reverse: Vec<char> = string.chars().collect();
reverse.reverse();
let reverse: String = reverse.into_iter().collect();
let is_palindrome = reverse == string;
println!("{is_palindrome}");
}