Skip to content

Commit

Permalink
349 350 using hash set in java instead of hash tree.
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyubobobo committed Nov 14, 2017
1 parent 446c346 commit 0c7c168
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions 0349-Intersection-of-Two-Arrays/java-0349/src/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// Author : liuyubobobo
/// Time : 2017-07-12

import java.util.TreeSet;
import java.util.HashSet;

/// Hash Set
/// Time complexity: O(len(nums1) + len(nums2))
Expand All @@ -11,11 +11,11 @@ public class Solution {

public int[] intersection(int[] nums1, int[] nums2) {

TreeSet<Integer> record = new TreeSet<Integer>();
HashSet<Integer> record = new HashSet<Integer>();
for(int num: nums1)
record.add(num);

TreeSet<Integer> resultSet = new TreeSet<Integer>();
HashSet<Integer> resultSet = new HashSet<Integer>();
for(int num: nums2)
if(record.contains(num))
resultSet.add(num);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// Author : liuyubobobo
/// Time : 2017-11-14

import java.util.TreeMap;
import java.util.HashMap;
import java.util.ArrayList;

/// Using Hash Map
Expand All @@ -12,7 +12,7 @@ public class Solution {

public int[] intersect(int[] nums1, int[] nums2) {

TreeMap<Integer, Integer> record = new TreeMap<Integer, Integer>();
HashMap<Integer, Integer> record = new HashMap<Integer, Integer>();
for(int num: nums1)
if(!record.containsKey(num))
record.put(num, 1);
Expand Down

0 comments on commit 0c7c168

Please sign in to comment.