Advertisement
jorupp

https://leetcode.com/problems/single-number-iii

Mar 21st, 2023
816
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function singleNumber(nums: number[]): number[] {
  2.     const seen = new Set<number>();
  3.     const seenTwice = new Set<number>();
  4.     for(const i of nums) {
  5.         if (seen.has(i)) {
  6.             seenTwice.add(i);
  7.         } else {
  8.             seen.add(i);
  9.         }
  10.     }
  11.  
  12.     return [...seen].filter(i => !seenTwice.has(i));
  13. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement