Skip to content

Commit 8f5489a

Browse files
committed
python-practice
1 parent a969bc1 commit 8f5489a

2 files changed

Lines changed: 190 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+
"示例 1:\n",
11+
"\n",
12+
"- 输入: nums1 = [1,2,2,1], nums2 = [2,2]\n",
13+
"- 输出: [2]\n",
14+
"\n",
15+
"示例 2:\n",
16+
"\n",
17+
"- 输入: nums1 = [4,9,5], nums2 = [9,4,9,8,4]\n",
18+
"- 输出: [9,4]\n",
19+
"\n",
20+
"说明:\n",
21+
"\n",
22+
"- 输出结果中的每个元素一定是唯一的。\n",
23+
"- 我们可以不考虑输出结果的顺序。\n",
24+
"\n",
25+
"#### 思路\n",
26+
"集合运算\n",
27+
"- ’&‘ 交集\n",
28+
"- ’|‘ 并集\n",
29+
"- ‘-’ 差集"
30+
]
31+
},
32+
{
33+
"cell_type": "code",
34+
"execution_count": 1,
35+
"metadata": {
36+
"ExecuteTime": {
37+
"end_time": "2019-07-03T16:13:47.514368Z",
38+
"start_time": "2019-07-03T16:13:47.510285Z"
39+
}
40+
},
41+
"outputs": [],
42+
"source": [
43+
"class Solution(object):\n",
44+
" def intersection(self, nums1, nums2):\n",
45+
" \"\"\"\n",
46+
" :type nums1: List[int]\n",
47+
" :type nums2: List[int]\n",
48+
" :rtype: List[int]\n",
49+
" \"\"\"\n",
50+
" return list(set(nums1) & set(nums2))"
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: 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+
"示例 1:\n",
11+
"\n",
12+
"- 输入: nums1 = [1,2,2,1], nums2 = [2,2]\n",
13+
"- 输出: [2]\n",
14+
"\n",
15+
"示例 2:\n",
16+
"\n",
17+
"- 输入: nums1 = [4,9,5], nums2 = [9,4,9,8,4]\n",
18+
"- 输出: [9,4]\n",
19+
"\n",
20+
"说明:\n",
21+
"\n",
22+
"- 输出结果中的每个元素一定是唯一的。\n",
23+
"- 我们可以不考虑输出结果的顺序。\n",
24+
"\n",
25+
"#### 思路\n",
26+
"集合运算\n",
27+
"- ’&‘ 交集\n",
28+
"- ’|‘ 并集\n",
29+
"- ‘-’ 差集"
30+
]
31+
},
32+
{
33+
"cell_type": "code",
34+
"execution_count": 1,
35+
"metadata": {
36+
"ExecuteTime": {
37+
"end_time": "2019-07-03T16:13:47.514368Z",
38+
"start_time": "2019-07-03T16:13:47.510285Z"
39+
}
40+
},
41+
"outputs": [],
42+
"source": [
43+
"class Solution(object):\n",
44+
" def intersection(self, nums1, nums2):\n",
45+
" \"\"\"\n",
46+
" :type nums1: List[int]\n",
47+
" :type nums2: List[int]\n",
48+
" :rtype: List[int]\n",
49+
" \"\"\"\n",
50+
" return list(set(nums1) & set(nums2))"
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+
}

0 commit comments

Comments
 (0)