Add single number challenge

This commit is contained in:
Jessica Kwok 2021-03-19 16:26:23 -07:00
parent fdfb4fff55
commit 935faca63a

View file

@ -0,0 +1,22 @@
# Challenge name: Single Number
#
# Given a non-empty array of integers nums, every element appears twice
# except for one. Find that single one.
#
# Follow up: Could you implement a solution with a linear runtime
# complexity and without using extra memory?
#
# @param {Integer[]} nums
# @return {Integer}
def single_number(nums)
end
nums = [2, 2, 1]
puts(single_number(nums))
# Output: 1
nums = [4, 1, 2, 1, 2]
puts(single_number(nums))
# Output: 4
nums = [1]
puts(single_number(nums))
# Output: 1