File tree Expand file tree Collapse file tree 1 file changed +29
-1
lines changed Expand file tree Collapse file tree 1 file changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -131,5 +131,33 @@ public int missingNumber(int[] nums) {
131131< p align= ' center' >
132132< img src= " ../pictures/qrcode.jpg" width= 200 >
133133< / p>
134+ ====== 其他语言代码======
134135
135- ====== 其他语言代码======
136+
137+
138+ ```python
139+ def missingNumber(self, nums: List [int ]) - > int :
140+ #思路1 ,位运算
141+ res = len(nums)
142+ for i,num in enumerate(nums):
143+ res ^ = i^ num
144+ return res
145+ ```
146+
147+ ```python
148+ def missingNumber(self, nums: List [int ]) - > int :
149+ #思路2 ,求和
150+ n = len(nums)
151+ return n* (n+ 1 )// 2-sum(nums)
152+ ```
153+
154+ ```python
155+ def missingNumber(self, nums: List [int ]) - > int :
156+ #思路3 ,防止整形溢出的优化
157+ res = len(nums)
158+ for i,num in enumerate(nums):
159+ res+= i- num
160+ return res
161+ ```
162+
163+ 事实上,在python3中不存在整数溢出的问题(只要内存放得下),思路3 的优化提升并不大,不过看上去有内味了哈...
You can’t perform that action at this time.
0 commit comments