Created
February 9, 2020 02:23
-
-
Save HauptJ/874b0281b616e12a276a2ebef34751fb to your computer and use it in GitHub Desktop.
961. N-Repeated Element in Size 2N Array - https://leetcode.com/problems/n-repeated-element-in-size-2n-array/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def repeatedNTimes(self, A: List[int]) -> int: | |
for i in range(len(A)): | |
if A.count(A[i]) == len(A)//2: | |
return A[i] | |
""" | |
Input: [1,2,3,3] | |
Output: 3 | |
size 2N | |
N+1 unique | |
N=2 | |
T = 3 | |
Input: [2,1,2,5,3,2] | |
Output: 2 | |
size 2N | |
N+1 unique | |
N=3 | |
T=2 | |
Input: [5,1,5,2,5,3,5,4] | |
Output: 5 | |
N 5 | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment