Diwali Offer!Flat 20% OFF
Enroll Now
PrakalpanaLive online tech training

195. Single Number

EasyDay 58 of 60Bit Manipulation & Math

Given a non-empty integer array nums in which every value appears exactly twice except one value that appears once, return that single value. Your solution should run in linear time and use only constant extra space.

Example 1
Input: nums = [2,2,1]
Output: 1
Example 2
Input: nums = [4,1,2,1,2]
Output: 4
The pairs of 1 and 2 cancel out, leaving 4.
Constraints
  • 1 <= nums.length <= 3 * 10^4
  • -3 * 10^4 <= nums[i] <= 3 * 10^4
  • Every element appears twice except for one
Hints
Frequently asked at: Amazon, Google, Apple, TCS, Infosys
Ctrl + Enter runs the examples

Not sure what to learn next?

A 1-on-1 session with an industry mentor and a roadmap built for you. How it works

  1. 1Discuss your goals
  2. 2Get a personal plan
  3. 3Start learning
Book for β‚Ή200/ 30 min