摘要:
一、题目描述 二、解法 class Solution { public int[] twoSum(int[] nums, int target) { /** * 方法1:暴力枚举。 * 时间复杂度O(n^2),空间复杂度O(1) */ /*for (int i = 0; i < nums.lengt 阅读全文
摘要:
一、题目描述 二、解法 class Solution { public String frequencySort(String s) { if (s == null || s.length() <= 2) return s; Map<Character,Integer> map = new Hash 阅读全文
摘要:
一、题目描述 二、解法 class Solution { public boolean isIsomorphic(String s, String t) { if (s.length() != t.length()) return false; /** * 方法1:使用HashMap,与LeetCo 阅读全文
摘要:
一、题目描述 二、解法 class Solution { public boolean wordPattern(String pattern, String s) { /** * 使用Map * 失败有两种情况: 1.key存在,经过查找字母对应的单词和这个单词不匹配; * 2.key不存在,但是这 阅读全文
摘要:
一、题目描述 二、解法 class Solution { public boolean isHappy(int n) { /** * 方法1:用Set检测循环 */ /*Set<Integer> set = new HashSet<>(); while (n != 1) { if (set.cont 阅读全文
摘要:
一、题目描述 二、解法 class Solution { public boolean isAnagram(String s, String t) { if (s.length() != t.length()) return false; int[] dict = new int[26]; /** 阅读全文
摘要:
一、题目描述 二、解法 class Solution { public int singleNumber(int[] nums) { /*Map<Integer,Integer> map = new HashMap<>(); for (int num : nums) { map.put(num, m 阅读全文