LeetCode Entry
3884. First Matching Character From Both Ends
Position of symmetrical equal char
3884. First Matching Character From Both Ends easy substack youtube
https://dmitrysamoylenko.com/leetcode/

Join me on Telegram
https://t.me/leetcode_daily_unstoppable/1562
Problem TLDR
Position of symmetrical equal char
Intuition
Can use .find operation
Approach
- or zip, make diff and indexOf(0)
Complexity
-
Time complexity: \(O(n)\)
-
Space complexity: \(O(n)\)
Code
fun firstMatchingIndex(s: String) =
s.zip(s.reversed()){a,b->a-b}.indexOf(0)
pub fn first_matching_index(s: String) -> i32 {
s.bytes().zip(s.bytes().rev()).position(|(a,b)|a==b).unwrap_or(!0)as _
}
Comments