Skip to content

Commit 88c92b4

Browse files
committed
add daily problem
1 parent b8d62db commit 88c92b4

File tree

2 files changed

+212
-0
lines changed

2 files changed

+212
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "progressive-borough",
6+
"metadata": {},
7+
"source": [
8+
"### [找到所有数组中消失的数字](https://leetcode-cn.com/problems/find-all-numbers-disappeared-in-an-array/)\n",
9+
"\n",
10+
"给定一个范围在`1 ≤ a[i] ≤ n` ( n = 数组大小 ) 的 整型数组,数组中的元素一些出现了两次,另一些只出现一次。\n",
11+
"\n",
12+
"找到所有在`[1, n]`范围之间没有出现在数组中的数字。\n",
13+
"\n",
14+
"您能在不使用额外空间且时间复杂度为`O(n)`的情况下完成这个任务吗? 你可以假定返回的数组不算在额外空间内。\n",
15+
"\n",
16+
"#### 示例:\n",
17+
"```\n",
18+
"输入:[4,3,2,7,8,2,3,1]\n",
19+
"输出: [5,6]\n",
20+
"```"
21+
]
22+
},
23+
{
24+
"cell_type": "code",
25+
"execution_count": 1,
26+
"id": "wanted-poker",
27+
"metadata": {},
28+
"outputs": [],
29+
"source": [
30+
"from typing import List\n",
31+
"\n",
32+
"def findDisappearedNumbers(nums: List[int]) -> List[int]:\n",
33+
" for i, n in enumerate(nums):\n",
34+
" if nums[abs(n) - 1] > 0:\n",
35+
" nums[abs(n) - 1] *= -1\n",
36+
" ans = []\n",
37+
" for i, n in enumerate(nums):\n",
38+
" if n > 0:\n",
39+
" ans.append(i + 1)\n",
40+
" return ans"
41+
]
42+
},
43+
{
44+
"cell_type": "code",
45+
"execution_count": 2,
46+
"id": "plastic-parent",
47+
"metadata": {},
48+
"outputs": [
49+
{
50+
"data": {
51+
"text/plain": [
52+
"[5, 6]"
53+
]
54+
},
55+
"execution_count": 2,
56+
"metadata": {},
57+
"output_type": "execute_result"
58+
}
59+
],
60+
"source": [
61+
"findDisappearedNumbers([4,3,2,7,8,2,3,1])"
62+
]
63+
}
64+
],
65+
"metadata": {
66+
"kernelspec": {
67+
"display_name": "Python 3",
68+
"language": "python",
69+
"name": "python3"
70+
},
71+
"language_info": {
72+
"codemirror_mode": {
73+
"name": "ipython",
74+
"version": 3
75+
},
76+
"file_extension": ".py",
77+
"mimetype": "text/x-python",
78+
"name": "python",
79+
"nbconvert_exporter": "python",
80+
"pygments_lexer": "ipython3",
81+
"version": "3.8.6"
82+
}
83+
},
84+
"nbformat": 4,
85+
"nbformat_minor": 5
86+
}

Diff for: algorithms/766-toeplitz-matrix.ipynb

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "coated-pilot",
6+
"metadata": {},
7+
"source": [
8+
"### [托普利茨矩阵](https://leetcode-cn.com/problems/toeplitz-matrix/)\n",
9+
"\n",
10+
"给你一个`m x n`的矩阵`matrix`。如果这个矩阵是托普利茨矩阵,返回`true`;否则,返回`false`。\n",
11+
"\n",
12+
"如果矩阵上每一条由左上到右下的对角线上的元素都相同,那么这个矩阵是**托普利茨矩阵**。\n",
13+
"\n",
14+
"#### 示例 1:\n",
15+
"```\n",
16+
"输入:matrix = [[1,2,3,4],[5,1,2,3],[9,5,1,2]]\n",
17+
"输出:true\n",
18+
"解释:\n",
19+
"在上述矩阵中, 其对角线为: \n",
20+
"\"[9]\", \"[5, 5]\", \"[1, 1, 1]\", \"[2, 2, 2]\", \"[3, 3]\", \"[4]\"\n",
21+
"各条对角线上的所有元素均相同, 因此答案是 True 。\n",
22+
"```\n",
23+
"\n",
24+
"#### 示例 2:\n",
25+
"```\n",
26+
"输入:matrix = [[1,2],[2,2]]\n",
27+
"输出:false\n",
28+
"解释:\n",
29+
"对角线 \"[1, 2]\" 上的元素不同。\n",
30+
"```\n",
31+
"\n",
32+
"#### 提示:\n",
33+
"- m == matrix.length\n",
34+
"- n == matrix[i].length\n",
35+
"- 1 <= m, n <= 20\n",
36+
"- 0 <= matrix[i][j] <= 99\n",
37+
" \n",
38+
"\n",
39+
"#### 进阶:\n",
40+
"- 如果矩阵存储在磁盘上,并且内存有限,以至于一次最多只能将矩阵的一行加载到内存中,该怎么办?\n",
41+
"- 如果矩阵太大,以至于一次只能将不完整的一行加载到内存中,该怎么办?"
42+
]
43+
},
44+
{
45+
"cell_type": "code",
46+
"execution_count": 1,
47+
"id": "occupational-crest",
48+
"metadata": {},
49+
"outputs": [],
50+
"source": [
51+
"from typing import List\n",
52+
"\n",
53+
"def isToeplitzMatrix(matrix: List[List[int]]) -> bool:\n",
54+
" m, n = len(matrix), len(matrix[0])\n",
55+
" for i in range(1, m):\n",
56+
" for j in range(1, n):\n",
57+
" if matrix[i][j] != matrix[i - 1][j - 1]:\n",
58+
" return False\n",
59+
" return True"
60+
]
61+
},
62+
{
63+
"cell_type": "code",
64+
"execution_count": 2,
65+
"id": "japanese-facility",
66+
"metadata": {},
67+
"outputs": [
68+
{
69+
"data": {
70+
"text/plain": [
71+
"True"
72+
]
73+
},
74+
"execution_count": 2,
75+
"metadata": {},
76+
"output_type": "execute_result"
77+
}
78+
],
79+
"source": [
80+
"isToeplitzMatrix([[1,2,3,4],[5,1,2,3],[9,5,1,2]])"
81+
]
82+
},
83+
{
84+
"cell_type": "code",
85+
"execution_count": 3,
86+
"id": "organizational-glass",
87+
"metadata": {},
88+
"outputs": [
89+
{
90+
"data": {
91+
"text/plain": [
92+
"False"
93+
]
94+
},
95+
"execution_count": 3,
96+
"metadata": {},
97+
"output_type": "execute_result"
98+
}
99+
],
100+
"source": [
101+
"isToeplitzMatrix([[1,2],[2,2]])"
102+
]
103+
}
104+
],
105+
"metadata": {
106+
"kernelspec": {
107+
"display_name": "Python 3",
108+
"language": "python",
109+
"name": "python3"
110+
},
111+
"language_info": {
112+
"codemirror_mode": {
113+
"name": "ipython",
114+
"version": 3
115+
},
116+
"file_extension": ".py",
117+
"mimetype": "text/x-python",
118+
"name": "python",
119+
"nbconvert_exporter": "python",
120+
"pygments_lexer": "ipython3",
121+
"version": "3.8.6"
122+
}
123+
},
124+
"nbformat": 4,
125+
"nbformat_minor": 5
126+
}

0 commit comments

Comments
 (0)