java.lang.Object
g0501_0600.s0540_single_element_in_a_sorted_array.Solution

public class Solution extends Object
540 - Single Element in a Sorted Array.<p>Medium</p> <p>You are given a sorted array consisting of only integers where every element appears exactly twice, except for one element which appears exactly once.</p> <p>Return <em>the single element that appears only once</em>.</p> <p>Your solution must run in <code>O(log n)</code> time and <code>O(1)</code> space.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [1,1,2,3,3,4,4,8,8]</p> <p><strong>Output:</strong> 2</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [3,3,7,7,10,11,11]</p> <p><strong>Output:</strong> 10</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= nums.length <= 10<sup>5</sup></code></li> <li><code>0 <= nums[i] <= 10<sup>5</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • singleNonDuplicate

      public int singleNonDuplicate(int[] nums)