2200. Find All K-Distant Indices in an Array
nums里与key值一样的复数index j,找出所有index i |i-j|<=k 并排序输出
public IList<int> FindKDistantIndices(int[] nums, int key, int k)
{
var hashset = new HashSet<int>();
for (int j = 0; j < nums.Length; j++)
{
if (nums[j] == key)
{
var start = Math.Max(0, j-k);
var end = Math.Min(j+k, nums.Length-1);
for (int i=start;i<=end;i++)
{
hashset.Add(i);
}
}
}
return hashset.ToList();
}
最近我以为不会走的几个老同事都走了
有个跟我差不多时间进来的同事最近偶尔突然请假,感觉也在偷面试
剩我走不掉了