mirror of
https://github.com/TheAlgorithms/Ruby
synced 2025-01-14 08:01:05 +01:00
22 lines
No EOL
500 B
Ruby
22 lines
No EOL
500 B
Ruby
# 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 |