My LeetCode grinding. Trying to do a problem a day.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

main.rs 430B

12345678910111213141516171819
  1. pub fn judge_circle(moves: String) -> bool {
  2. let mut x = 0;
  3. let mut y = 0;
  4. for m in moves.chars() {
  5. match m {
  6. 'U' => x = x + 1,
  7. 'D' => x = x - 1,
  8. 'L' => y = y + 1,
  9. 'R' => y = y - 1,
  10. _ => {},
  11. }
  12. }
  13. return y == 0 && x == 0;
  14. }
  15. pub fn main() {
  16. println!("Expected: true");
  17. println!("Got: {}", judge_circle("UDRULD".to_string()));
  18. }