|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "给定一个仅包含大小写字母和空格 ' ' 的字符串,返回其最后一个单词的长度。\n", |
| 8 | + "\n", |
| 9 | + "如果不存在最后一个单词,请返回 0 。\n", |
| 10 | + "\n", |
| 11 | + "说明:一个单词是指由字母组成,但不包含任何空格的字符串。\n", |
| 12 | + "\n", |
| 13 | + "示例:\n", |
| 14 | + "\n", |
| 15 | + "- 输入: \"Hello World\"\n", |
| 16 | + "- 输出: 5" |
| 17 | + ] |
| 18 | + }, |
| 19 | + { |
| 20 | + "cell_type": "code", |
| 21 | + "execution_count": 3, |
| 22 | + "metadata": { |
| 23 | + "ExecuteTime": { |
| 24 | + "end_time": "2019-07-02T04:13:03.283648Z", |
| 25 | + "start_time": "2019-07-02T04:13:03.270703Z" |
| 26 | + } |
| 27 | + }, |
| 28 | + "outputs": [ |
| 29 | + { |
| 30 | + "data": { |
| 31 | + "text/plain": [ |
| 32 | + "0" |
| 33 | + ] |
| 34 | + }, |
| 35 | + "execution_count": 3, |
| 36 | + "metadata": {}, |
| 37 | + "output_type": "execute_result" |
| 38 | + } |
| 39 | + ], |
| 40 | + "source": [ |
| 41 | + "class Solution(object):\n", |
| 42 | + " def lengthOfLastWord(self, s):\n", |
| 43 | + " \"\"\"\n", |
| 44 | + " :type s: str\n", |
| 45 | + " :rtype: int\n", |
| 46 | + " \"\"\"\n", |
| 47 | + " if len(s) == 0:\n", |
| 48 | + " return 0\n", |
| 49 | + " elif len(s.split()) == 0:\n", |
| 50 | + " return 0\n", |
| 51 | + " else:\n", |
| 52 | + " return len(s.split()[-1])\n", |
| 53 | + " \n", |
| 54 | + "# s = \"Hello World\"\n", |
| 55 | + "s = \" \"\n", |
| 56 | + "solution = Solution()\n", |
| 57 | + "solution.lengthOfLastWord(s)" |
| 58 | + ] |
| 59 | + }, |
| 60 | + { |
| 61 | + "cell_type": "code", |
| 62 | + "execution_count": null, |
| 63 | + "metadata": {}, |
| 64 | + "outputs": [], |
| 65 | + "source": [] |
| 66 | + } |
| 67 | + ], |
| 68 | + "metadata": { |
| 69 | + "kernelspec": { |
| 70 | + "display_name": "python pratice", |
| 71 | + "language": "python", |
| 72 | + "name": "env_name" |
| 73 | + }, |
| 74 | + "language_info": { |
| 75 | + "codemirror_mode": { |
| 76 | + "name": "ipython", |
| 77 | + "version": 3 |
| 78 | + }, |
| 79 | + "file_extension": ".py", |
| 80 | + "mimetype": "text/x-python", |
| 81 | + "name": "python", |
| 82 | + "nbconvert_exporter": "python", |
| 83 | + "pygments_lexer": "ipython3", |
| 84 | + "version": "3.7.1" |
| 85 | + }, |
| 86 | + "toc": { |
| 87 | + "base_numbering": 1, |
| 88 | + "nav_menu": {}, |
| 89 | + "number_sections": true, |
| 90 | + "sideBar": true, |
| 91 | + "skip_h1_title": false, |
| 92 | + "title_cell": "Table of Contents", |
| 93 | + "title_sidebar": "Contents", |
| 94 | + "toc_cell": false, |
| 95 | + "toc_position": {}, |
| 96 | + "toc_section_display": true, |
| 97 | + "toc_window_display": false |
| 98 | + } |
| 99 | + }, |
| 100 | + "nbformat": 4, |
| 101 | + "nbformat_minor": 2 |
| 102 | +} |
0 commit comments