<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智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                Given a non-negative integer represented as a non-empty array of digits, plus one to the integer. You may assume the integer do not contain any leading zero, except the number 0 itself. The digits are stored such that the most significant digit is at the head of the list. ~~~ public class Solution { public int[] plusOne(int[] digits) { int carry = 0, i = digits.length-1; digits[i]+=1; while(digits[i]>=10){ digits[i--]-=10; if(i>=0) digits[i]+=1; else { carry =1; break; } } if(carry ==0) return digits; int[] res = new int[digits.length+1]; for(i=0; i<digits.length;i++){ res[i+1] = digits[i]; } res[0]=1; return res; } } public class Solution { public int[] plusOne(int[] digits) { int length; length = digits.length; for(int i = length-1; i>=0; i--){ if(digits[i]<9){ digits[i]++; break; }else{ digits[i]=0; } } int[] newdigits; if(digits[0]==0){ newdigits = new int[digits.length+1]; newdigits[0]=1; for(int i=1;i<newdigits.length;i++){ newdigits[i]=digits[i-1]; } }else{ newdigits = new int[digits.length]; for(int i=0;i<digits.length;i++){ newdigits[i]=digits[i]; } } return newdigits; } } 先對原數組進行處理。從數組最后一位開始往前檢查,如果當前數字是<9的,說明你加1無需進位,從循環跳出即可,如果當前數字等于9,說明加1涉及進位,且加1后當前數字應記為0,繼續循環處理。 當對原數組處理完后,還需要判斷當前第0位是不是已經變為0了,如果已經變為0了說明是類似99+1這種,需要進位。其他則不需要。 一般對數字進行操作的題都要考慮邊界,尤其是溢出問題。 ~~~
                  <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>

                              哎呀哎呀视频在线观看