Class Solution

java.lang.Object
g0101_0200.s0137_single_number_ii.Solution

public class Solution extends Object
137 - Single Number II.<p>Medium</p> <p>Given an integer array <code>nums</code> where every element appears <strong>three times</strong> except for one, which appears <strong>exactly once</strong>. <em>Find the single element and return it</em>.</p> <p>You must implement a solution with a linear runtime complexity and use only constant extra space.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [2,2,3,2]</p> <p><strong>Output:</strong> 3</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [0,1,0,1,0,1,99]</p> <p><strong>Output:</strong> 99</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= nums.length <= 3 * 10<sup>4</sup></code></li> <li><code>-2<sup>31</sup> <= nums[i] <= 2<sup>31</sup> - 1</code></li> <li>Each element in <code>nums</code> appears exactly <strong>three times</strong> except for one element which appears <strong>once</strong>.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • singleNumber

      public int singleNumber(int[] nums)