#1133
Easy Algorithms Largest unique number
Array Hash Table Sorting
71.3% acceptance
Mar 31, 2026
356
18
Given an integer array nums, return the largest integer that only occurs once. If no integer occurs once, return -1.
Solution
Rust
Time O(n)
Space O(1)
impl Solution {
pub fn largest_unique_number(nums: Vec<i32>) -> i32 {
let mut count = [0u16; 1001];
for &n in &nums {
count[n as usize] += 1;
}
for i in (0..=1000).rev() {
if count[i] == 1 {
return i as i32;
}
}
-1
}
}