<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                >[success] # 反轉整數 ~~~ 給定一個 32 位有符號整數,將整數中的數字進行反轉。 注意: 假設我們的環境只能存儲 32 位有符號整數,其數值范圍是 [?2^31, 2^31 ? 1]。根據這個假設,如果反轉后的整數溢出, 則返回 0。 ~~~ * 示例 ~~~ 輸入: 123 輸出: 321 ~~~ >[danger] ##### 解題PYTHON * 思路 ~~~ 1.利用切片[start_index:end_index:step] 2.切片第一個值 是從哪里開始,第二個是在哪里結束,第三個是跳躍幾個,顧頭不顧腚 ~~~ * 個人最開始想法 ~~~ class Solution: def reverse(self, x): """ :type x: int :rtype: int """ if x<0: a = int("-"+str(x)[:0:-1]) print(a) if a < (-2**31): return 0 else: return a elif x>=0: a = int(str(x)[::-1]) if a > (2**31-1) : return 0 else: return a ~~~ * 查詢后別人的方法 ~~~ class Solution: def reverse(self, x): """ :type x: int :rtype: int """ x = int( str(x)[::-1] if x>=0 else "-"+str(x)[:0:-1]) return 0 if x>2**31-1 or x<-2**31 else x ~~~ * 最快方法 ~~~ 1.bit_length() 一個數的二進制長度 2.一個數的二進制長度等于長度二的次冪加1 ~~~ ~~~ class Solution: def reverse(self, x): """ :type x: int :rtype: int """ flag = 0 if x > 0: flag = 1 else: flag = -1 s = str(abs(x))[::-1] n = int(s) * flag return n if n.bit_length() < 32 else 0 ~~~ >[danger] ##### 解題JAVASPRICT ~~~ 1.Math.sign() -- Math.sign方法用來判斷一個數到底是正數、負數、還是零 2.字符串.abs(x).toString().split("").reverse().join("") ~~~ ~~~ /** * @param {number} x * @return {number} */ var reverse = function(x) { let numberList = Math.sign(x)*Math.abs(x).toString().split("").reverse().join("") return (numberList<Math.pow(-2,31)||numberList>Math.pow(2,31)-1)?0:numberList }; ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看