资讯中心

leetcode 耗时100 1848. Minimum Distance to the Target Element

📅 2026/10/17 1:05:14
leetcode 耗时100 1848. Minimum Distance to the Target Element
Problem: 1848. 到目标元素的最小距离耗时100%Codeclass Solution { public: int getMinDistance(vectorint nums, int target, int start) { int n nums.size(), mi INT_MAX; for(int i start; i n; i) { if(nums[i] target) { mi min(mi, abs(i - start)); break; } } for(int i start - 1; i 0; i--) { if(nums[i] target) { mi min(mi, abs(i - start)); break; } } return mi; } };

看完文章,想为自己的企业也做一次专业网站诊断?

尧图顾问免费为您评估现有网站,并给出建站/改版建议与报价方案。

免费获取方案