Javascript solution


  • 0
    R

    /**

    • @param {number[]} nums1
    • @param {number[]} nums2
    • @return {number[]}
      /
      var intersect = function intersect(a, b) {
      var result = [];
      a.sort(function(a, b){return a-b});
      b.sort(function(a, b){return a-b});
      while( a.length > 0 && b.length > 0 )
      {
      if (a[0] < b[0] ){
      a.shift();
      }
      else if (a[0] > b[0] ){
      b.shift();
      }
      else /
      they're equal */
      {
      result.push(a.shift());
      b.shift();
      }
      }

    return result;
    };


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.