javascript 86ms solution


  • 0
    F

    /**

    • @param {number[]} nums1
    • @param {number[]} nums2
    • @return {number[]}
      */
      var intersection = function(nums1, nums2) {
      var res = [];
      var resDic = {}, nums1Dic = {}, nums2Dic = {};
      for ( var i = 0; i != nums1.length; ++i ) {
      nums1Dic[nums1[i]] = 'y';
      }
      for ( var i = 0; i != nums2.length; ++i) {
      if ( nums1Dic[nums2[i]] ) {
      resDic[nums2[i]] = 'y';
      }
      }
      for ( var key in resDic ) {
      res.push(parseInt(key));
      }
      return res;
      };

Log in to reply
 

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