#521
Easy Algorithms Longest uncommon subsequence i
String
62.0% acceptance
Feb 19, 2026
116
353
Given two strings a and b, return the length of the longest uncommon subsequence between a and b. If no such uncommon subsequence exists, return -1.
An uncommon subsequence between two strings is a string that is a subsequence of exactly one of them.
Solution
Rust
Time O(n)
Space O(1)
impl Solution {
pub fn find_lu_slength(a: String, b: String) -> i32 {
if a == b { -1 } else { a.len().max(b.len()) as i32 }
}
}