Skip to content

Instantly share code, notes, and snippets.

@lomholdt
Created November 5, 2020 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lomholdt/10d178fc0b5fea355a1468ca09722436 to your computer and use it in GitHub Desktop.
Save lomholdt/10d178fc0b5fea355a1468ca09722436 to your computer and use it in GitHub Desktop.
fn main() {
let result = is_palindrome("racecar"); // Should be true
println!("{}", result);
}
fn is_palindrome(name: &str) -> bool {
let half = name.len() / 2;
name
.bytes()
.take(half)
.eq(name
.bytes()
.rev()
.take(half))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment