直接觀看文章

LifeJourney

We only live once.

  • Blog
  • Home
  • 聯絡

LeetCode – 190. Reverse Bits

On 15 四月, 2022 由Kevin Nien撰寫In LeetCode、Uncategorized

題目連結: https://leetcode.com/problems/reverse-bits/

參考解法: https://leetcode.com/problems/reverse-bits/discuss/1583277/Swift-Bit-manipulation-with-explanation

func reverseBits(_ n: Int) -> Int {
    var tmp = n
    var result = 0
    for _ in 1 ... 32 {
        let val = tmp & 1
        result = result << 1 + val
        tmp = tmp >> 1
    }
    return result
}

Share this:

  • Twitter
  • Facebook

請按讚:

喜歡 正在載入...

相關

文章分頁導航

Previous

LeetCode – 78. Subsets

Next

LeetCode – 654. Maximum Binary Tree

  • Uncategorized
  • Daily notes
  • Poem
  • Movies
  • Sport
  • Workout
  • Travel
  • Art
  • Technology sharing
    • IOS Development
      • RxSwift
    • LeetCode
    • SystemDesignPractice
  • Sādhanā
  • Vocal music

在 WordPress.com 建立網站或網誌 佈景主題:lovecraft,發表者:Anders Noren。
  • 追蹤 已追蹤
    • LifeJourney
    • 已經有 WordPress.com 帳號了?立即登入。
    • LifeJourney
    • 自訂
    • 追蹤 已追蹤
    • 註冊
    • 登入
    • 複製短網址
    • 回報此內容
    • 以閱讀器檢視
    • 管理訂閱
    • 收合此列
%d 位部落客按了讚: