摘要:
public class Solution { public boolean isAnagram(String s, String t) { char[] first = s.toCharArray(); Arrays.sort(first); cha... 阅读全文
摘要:
public class Solution { public int titleToNumber(String s) { int result = 0; int tmp = 1; for (int i = s.length() - 1; i >= 0;... 阅读全文
摘要:
public class Solution { public int longestConsecutive(int[] nums) { HashSet set = new HashSet(); for (int num : nums) { se... 阅读全文
摘要:
public class Solution { private int result = 0; public int longestConsecutive(TreeNode root) { if (root == null) { return 0; ... 阅读全文
摘要:
public class Solution { public int lengthOfLIS(int[] nums) { int length = nums.length; List record = new ArrayList(); for (int... 阅读全文
摘要:
public class Solution { public boolean wordPatternMatch(String pattern, String str) { return helper(pattern, str, new HashMap(), new HashMap... 阅读全文
摘要:
用的dfs,但是感觉这个方法应该不是最优的,否则这个题目不应该是hardpublic class Solution { int up = Integer.MAX_VALUE; int low = Integer.MIN_VALUE; int left = Integer.MAX_V... 阅读全文
摘要:
相当tricky的一道题目,我怀疑在面试的时候有人能在45分钟想出来,我参考了一下https://leetcode.com/discuss/72215/java-dp-solution-with-detailed-explanation-o-n-3这个人的思路。public class Soluti... 阅读全文
摘要:
public class Solution { public int minCostII(int[][] costs) { int n = costs.length; if (n == 0) { return 0; } ... 阅读全文
摘要:
public class Solution { public ListNode removeElements(ListNode head, int val) { ListNode dummy = new ListNode(0); dummy.next = head;... 阅读全文