iT邦幫忙

0

自主學習30日-LeetCode 268:Missing Number

  • 分享至 

  • xImage
  •  

268.Missing Number

題目

給定一個包含 0 到 n 之間的 n 個不同數字 的陣列,
找出陣列中缺少的那個數字。

解題思路

1.計算理論總和 sum = n * (n + 1) / 2

2.實際陣列總和 actualSum

3.差值 = 缺少的數

https://ithelp.ithome.com.tw/upload/images/20251020/20169298d5ho7fwuDP.pnghttps://ithelp.ithome.com.tw/upload/images/20251020/20169298wliVboUKHQ.png


圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言