...

/

Solution Review: Finding the First Unique Integer in an Array

Solution Review: Finding the First Unique Integer in an Array

This review provides a detailed analysis of solving the "Finding the First Unique Integer in an Array" challenge.

Solution: Brute force

Press + to interact
fn find_first_unique(arr: &[i32]) -> i32 {
let mut is_repeated = false;
for i in 0..arr.len(){
for j in 0..arr.len(){
if arr[i] == arr[j] && i != j {
is_repeated = true;
}
}
if is_repeated == false {
return arr[i];
}
is_repeated = false;
}
return -1;
}

Start from the first element, and traverse through the whole array by comparing it with all the other elements to see if any element is equal to it. If so, skip to the next element and repeat. If not, then this is the first unique element in the array.

Time complexity

The time complexity of this solution is O(n2 ...

Access this course and 1400+ top-rated courses and projects.