961. N-Repeated Element in Size 2N Array
Last updated
Last updated
In a array A
of size 2N
, there are N+1
unique elements, and exactly one of these elements is repeated N times.
Return the element repeated N
times.
Example 1:
Example 2:
N-Repeated 因為當長度為 2N 時,會有 N+1 個位置是放置重複的數字 先將其按照順序排列,中間的數字必為其重複的 但有例外是當重複的是在最前或最後時
Random 隨機於自陣列中抽取兩個數字來比對,如是相同的馬上回傳