Skip to content

Commit 8ee9158

Browse files
committed
python-practice
1 parent 6e4339a commit 8ee9158

4 files changed

Lines changed: 394 additions & 0 deletions

File tree

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"#### 题目描述\n",
8+
"统计字符串中的单词个数,这里的单词指的是连续的不是空格的字符。\n",
9+
"\n",
10+
"请注意,你可以假定字符串里不包括任何不可打印的字符。\n",
11+
"\n",
12+
"示例:\n",
13+
"\n",
14+
"- 输入: \"Hello, my name is John\"\n",
15+
"- 输出: 5"
16+
]
17+
},
18+
{
19+
"cell_type": "code",
20+
"execution_count": 1,
21+
"metadata": {
22+
"ExecuteTime": {
23+
"end_time": "2019-07-02T04:05:48.264660Z",
24+
"start_time": "2019-07-02T04:05:48.247584Z"
25+
}
26+
},
27+
"outputs": [
28+
{
29+
"data": {
30+
"text/plain": [
31+
"5"
32+
]
33+
},
34+
"execution_count": 1,
35+
"metadata": {},
36+
"output_type": "execute_result"
37+
}
38+
],
39+
"source": [
40+
"class Solution(object):\n",
41+
" def countSegments(self, s):\n",
42+
" \"\"\"\n",
43+
" :type s: str\n",
44+
" :rtype: int\n",
45+
" \"\"\"\n",
46+
" return len(s.split())\n",
47+
" \n",
48+
"s = \"Hello, my name is John\"\n",
49+
"solution = Solution()\n",
50+
"solution.countSegments(s)"
51+
]
52+
},
53+
{
54+
"cell_type": "code",
55+
"execution_count": null,
56+
"metadata": {},
57+
"outputs": [],
58+
"source": []
59+
}
60+
],
61+
"metadata": {
62+
"kernelspec": {
63+
"display_name": "python pratice",
64+
"language": "python",
65+
"name": "env_name"
66+
},
67+
"language_info": {
68+
"codemirror_mode": {
69+
"name": "ipython",
70+
"version": 3
71+
},
72+
"file_extension": ".py",
73+
"mimetype": "text/x-python",
74+
"name": "python",
75+
"nbconvert_exporter": "python",
76+
"pygments_lexer": "ipython3",
77+
"version": "3.7.1"
78+
},
79+
"toc": {
80+
"base_numbering": 1,
81+
"nav_menu": {},
82+
"number_sections": true,
83+
"sideBar": true,
84+
"skip_h1_title": false,
85+
"title_cell": "Table of Contents",
86+
"title_sidebar": "Contents",
87+
"toc_cell": false,
88+
"toc_position": {},
89+
"toc_section_display": true,
90+
"toc_window_display": false
91+
}
92+
},
93+
"nbformat": 4,
94+
"nbformat_minor": 2
95+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"#### 题目描述\n",
8+
"统计字符串中的单词个数,这里的单词指的是连续的不是空格的字符。\n",
9+
"\n",
10+
"请注意,你可以假定字符串里不包括任何不可打印的字符。\n",
11+
"\n",
12+
"示例:\n",
13+
"\n",
14+
"- 输入: \"Hello, my name is John\"\n",
15+
"- 输出: 5"
16+
]
17+
},
18+
{
19+
"cell_type": "code",
20+
"execution_count": 1,
21+
"metadata": {
22+
"ExecuteTime": {
23+
"end_time": "2019-07-02T04:05:48.264660Z",
24+
"start_time": "2019-07-02T04:05:48.247584Z"
25+
}
26+
},
27+
"outputs": [
28+
{
29+
"data": {
30+
"text/plain": [
31+
"5"
32+
]
33+
},
34+
"execution_count": 1,
35+
"metadata": {},
36+
"output_type": "execute_result"
37+
}
38+
],
39+
"source": [
40+
"class Solution(object):\n",
41+
" def countSegments(self, s):\n",
42+
" \"\"\"\n",
43+
" :type s: str\n",
44+
" :rtype: int\n",
45+
" \"\"\"\n",
46+
" return len(s.split())\n",
47+
" \n",
48+
"s = \"Hello, my name is John\"\n",
49+
"solution = Solution()\n",
50+
"solution.countSegments(s)"
51+
]
52+
},
53+
{
54+
"cell_type": "code",
55+
"execution_count": null,
56+
"metadata": {},
57+
"outputs": [],
58+
"source": []
59+
}
60+
],
61+
"metadata": {
62+
"kernelspec": {
63+
"display_name": "python pratice",
64+
"language": "python",
65+
"name": "env_name"
66+
},
67+
"language_info": {
68+
"codemirror_mode": {
69+
"name": "ipython",
70+
"version": 3
71+
},
72+
"file_extension": ".py",
73+
"mimetype": "text/x-python",
74+
"name": "python",
75+
"nbconvert_exporter": "python",
76+
"pygments_lexer": "ipython3",
77+
"version": "3.7.1"
78+
},
79+
"toc": {
80+
"base_numbering": 1,
81+
"nav_menu": {},
82+
"number_sections": true,
83+
"sideBar": true,
84+
"skip_h1_title": false,
85+
"title_cell": "Table of Contents",
86+
"title_sidebar": "Contents",
87+
"toc_cell": false,
88+
"toc_position": {},
89+
"toc_section_display": true,
90+
"toc_window_display": false
91+
}
92+
},
93+
"nbformat": 4,
94+
"nbformat_minor": 2
95+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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

Comments
 (0)