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();
}
最近我以為不會走的幾個老同事都走了
有個跟我差不多時間進來的同事最近偶爾突然請假,感覺也在偷面試
剩我走不掉了