Skip to main content
Back to problems
#3062
Easy Algorithms

Winner of the linked list game

Linked List
77.6% acceptance
Mar 31, 2026
32
5

No description available.

Solution

Rust
Time O(n)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn game_result(head: Option<Box<ListNode>>) -> String {
    let mut even_score = 0i32;
    let mut odd_score = 0i32;
    let mut cur = &head;
    while let Some(even_node) = cur {
      let odd_node = even_node.next.as_ref().unwrap();
      if even_node.val > odd_node.val {
        even_score += 1;
      } else if odd_node.val > even_node.val {
        odd_score += 1;
      }
      cur = &odd_node.next;
    }
    match even_score.cmp(&odd_score) {
      std::cmp::Ordering::Greater => "Even".to_string(),
      std::cmp::Ordering::Less => "Odd".to_string(),
      std::cmp::Ordering::Equal => "Tie".to_string(),
    }
  }
}