<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智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # Length of Last Word ### Source - leetcode: [Length of Last Word | LeetCode OJ](https://leetcode.com/problems/length-of-last-word/) - lintcode: [(422) Length of Last Word](http://www.lintcode.com/en/problem/length-of-last-word/) ~~~ Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string. If the last word does not exist, return 0. Have you met this question in a real interview? Yes Example Given s = "Hello World", return 5. Note A word is defined as a character sequence consists of non-space characters only. ~~~ ### 題解 關鍵點在于確定最后一個字符串之前的空格,此外還需要考慮末尾空格這一特殊情況,故首先除掉右邊的空白字符比較好。 ### Java ~~~ public class Solution { /** * @param s A string * @return the length of last word */ public int lengthOfLastWord(String s) { if (s == null | s.isEmpty()) return 0; // trim right space int begin = 0, end = s.length(); while (end > 0 && s.charAt(end - 1) == ' ') { end--; } // find the last space for (int i = 0; i < end; i++) { if (s.charAt(i) == ' ') { begin = i + 1; } } return end - begin; } } ~~~ ### 源碼分析 兩根指針。 ### 復雜度分析 遍歷一次,時間復雜度 O(n)O(n)O(n).
                  <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>

                              哎呀哎呀视频在线观看