ARTICLE DETAIL

资讯详情

深耕网站建设与运营推广的一线实战洞察。

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

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; } };
返回列表