File tree Expand file tree Collapse file tree 5 files changed +6
-22
lines changed
0287 Find the Duplicate Number Expand file tree Collapse file tree 5 files changed +6
-22
lines changed Original file line number Diff line number Diff line change 60
60
# ## Thought Process
61
61
62
62
1 . two for loop to check the numbers
63
- - Implement
64
-
65
- ```python
66
- class Solution:
67
- def findDuplicate(self , nums: List[int ]) -> int :
68
- """
69
- 1. using Gauss Algorithm $sum=(1+n)*(n)/2$
70
- 2. sum the array
71
- 3. subtract the summation of input array and the without one
72
- """
73
-
74
- sumWithoutDuplicate = (1 + len (nums) - 1 )* (len (nums) - 1 )/ 2
75
- sum = 0
76
- for num in nums:
77
- sum + = num
78
- return int (sum - sumWithoutDuplicate)
79
- ```
80
-
81
63
82
64
# ## Complexity
83
65
132
114
133
115

134
116
117
+ 
118
+
135
119
- 運用此原理進行 Binary search 找出重複的值
136
120
1 . lowerBound = 1 , upperBound= len (nums) - 1
137
121
2 . 當 lowerBound < upperBound
186
170
187
171
- 原理
188
172
189
- 
173
+ 
190
174
191
175
- Linked List Cycle Detection
192
176
193
- 
177
+ 
194
178
195
179
- Find the entry point of the cycle
196
180
197
- 
181
+ 
198
182
199
183
- implement
200
184
249
233
```
250
234
251
235
- [Leetcode 287 Find the Duplicate Number](https:// www.youtube.com/ watch? v = zQ6eAdtDeqg)
252
- - ** [LeetCode 287 Find the Duplicate Number (Python)](https:// maxming0.github.io/ 2020 / 06 / 25 / Find- the- Duplicate- Number/ )**
236
+ - [LeetCode 287 Find the Duplicate Number (Python)](https:// maxming0.github.io/ 2020 / 06 / 25 / Find- the- Duplicate- Number/ )
You can’t perform that action at this time.
0 commit comments