This file contains hidden or 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
| public boolean isMatch(String s, String p) { | |
| if (p.length() == 0) { | |
| return s.length() == 0; | |
| } | |
| // case 1: when the second char of p is NOT '*', simple | |
| if (p.length() == 1 || p.charAt(1) != '*') { | |
| if (s.length() < 1) { | |
| return false; | |
| } else if ((p.charAt(0) != s.charAt(0)) && (p.charAt(0) != '.')) { |
This file contains hidden or 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
| import java.util.HashMap; | |
| import java.util.HashSet; | |
| import java.util.LinkedList; | |
| import java.util.Map; | |
| import java.util.Queue; | |
| import java.util.Set; | |
| public class AlienDictionary_graph { | |
| public String alienOrder(String[] words) { | |
| if (words == null) return null; |
This file contains hidden or 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
| public class GasStation_greedy { | |
| public int canCompleteCircuit(int[] gas, int[] cost) { | |
| if (gas == null || cost == null || gas.length == 0 || cost.length == 0 || gas.length != cost.length) | |
| return -1; | |
| int len = gas.length; | |
| int delta = 0; | |
| int total = 0; | |
| int start_station = -1; | |
This file contains hidden or 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
| import java.util.Arrays; | |
| public class Candy_Greedy { | |
| // faster. two scans from left, then from right | |
| public int candyTwoScanFast(int[] ratings) { | |
| if (ratings == null || ratings.length == 0) return 0; | |
| int len = ratings.length; | |
| int tot = 0; | |
| int[] candy = new int[len]; |