-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Files are now organized into folders named for their respective approach. Any files that were created for studying will not have a number prefix as they did not originate from leetcode/CTCI.
- Loading branch information
Sean Prashad
authored and
Sean Prashad
committed
Jul 23, 2019
1 parent
27bc0c2
commit fbbe6c6
Showing
92 changed files
with
213 additions
and
3,034 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
*.class | ||
.vscode/ |
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class Majority_Element_169 { | ||
public static int majorityElement(int[] nums) { | ||
Map<Integer, Integer> hm = new HashMap<>(); | ||
int n = nums.length; | ||
int result = 0; | ||
|
||
for (int i = 0; i < n; i++) { | ||
hm.put(nums[i], hm.getOrDefault(nums[i], 0) + 1); | ||
if (hm.get(nums[i]) > n / 2) { | ||
result = nums[i]; | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class Intersection_of_Two_Arrays_II_350 { | ||
public static int[] intersect(int[] nums1, int[] nums2) { | ||
Map<Integer, Integer> hm = new HashMap<>(); | ||
List<Integer> intersection = new ArrayList<>(); | ||
|
||
for (int i = 0; i < nums1.length; i++) { | ||
hm.put(nums1[i], hm.getOrDefault(nums1[i], 0) + 1); | ||
} | ||
|
||
for (int i = 0; i < nums2.length; i++) { | ||
int freq = hm.getOrDefault(nums2[i], 0); | ||
if (freq > 0) { | ||
intersection.add(nums2[i]); | ||
hm.put(nums2[i], --freq); | ||
} | ||
} | ||
|
||
int[] result = new int[intersection.size()]; | ||
int idx = 0; | ||
for (int commonVal : intersection) { | ||
result[idx++] = commonVal; | ||
} | ||
|
||
return result; | ||
} | ||
} |
Oops, something went wrong.