diff --git a/dart/single_number.dart b/dart/single_number.dart new file mode 100644 index 0000000..dd0525e --- /dev/null +++ b/dart/single_number.dart @@ -0,0 +1,17 @@ +/* +Given a non-empty array of integers nums, every element appears twice except for one. Find that single one. + +You must implement a solution with a linear runtime complexity and use only constant extra space. +*/ + +class Solution { + int singleNumber(List nums) { + int ans = 0; + + for (final int num in nums) { + ans ^= num; + } + + return ans; + } +}