Re: [閒聊] 每日leetcode
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();
}
最近我以為不會走的幾個老同事都走了
有個跟我差不多時間進來的同事最近偶爾突然請假,感覺也在偷面試
剩我走不掉了
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.249.75.183 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1750777569.A.AB3.html
推
06/24 23:06,
5月前
, 1F
06/24 23:06, 1F
→
06/24 23:08,
5月前
, 2F
06/24 23:08, 2F
討論串 (同標題文章)
完整討論串 (本文為第 1452 之 1548 篇):