From a467de459b55b6f0c1924cecaecd2cd396be1942 Mon Sep 17 00:00:00 2001 From: li_chx Date: Mon, 20 Apr 2026 09:20:43 +0800 Subject: [PATCH] =?UTF-8?q?2078.=20=E4=B8=A4=E6=A0=8B=E9=A2=9C=E8=89=B2?= =?UTF-8?q?=E4=B8=8D=E5=90=8C=E4=B8=94=E8=B7=9D=E7=A6=BB=E6=9C=80=E8=BF=9C?= =?UTF-8?q?=E7=9A=84=E6=88=BF=E5=AD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index 92f5252..9da8ecb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,21 +2,19 @@ mod arr; struct Solution {} impl Solution { - pub fn max_distance(nums1: Vec, nums2: Vec) -> i32 { + pub fn max_distance(colors: Vec) -> i32 { let mut ans = 0; - for i in 0..nums1.len() { - let mut idx = nums2.partition_point(|&x| x >= nums1[i]); - if idx == 0 { - continue; + for i in 0..colors.len() { + for j in ((i + 1)..colors.len()).rev() { + if colors[i] != colors[j] { + ans = ans.max((j - i) as i32); + } } - idx -= 1; - ans = ans.max(idx as i32 - i as i32); } ans } } fn main() { - println!("{:?}", Solution::max_distance(vec![55,30,5,4,2],vec![100,20,10,10,5])); + println!("{:?}", Solution::max_distance(vec![1, 8, 3, 8, 3])); } -