随笔分类 - 哈希表
摘要:class Solution { public int findLength(int[] nums1, int[] nums2) { int ans = 0, len1 = nums1.length, len2 = nums2.length; for(int i = 0; i < len1; i++
阅读全文
摘要:public String minWindow(String s, String t) { // 穷尽每个字符,看是否含有这个子字符串 // 枚举所有子串,并放入 // 从字串出发,用双指针枚举-> Map<Character, Integer> smap = new HashMap<>(); Ma
阅读全文
摘要:public int[] intersection(int[] nums1, int[] nums2) { Set<Integer> set1 = new HashSet<>(), set2 = new HashSet<>(); for(int a: nums1) set1.add(a); List
阅读全文
摘要:public int[] dailyTemperatures(int[] temperatures) { int len = temperatures.length; LinkedList<Integer>[] table = new LinkedList[101]; for(int i = 30;
阅读全文
摘要:class Solution { public boolean isAnagram(String s, String t) { if (s.length() != t.length()) { return false; } int[] table = new int[26]; for (int i
阅读全文
摘要:public List<Integer> inorderTraversal(TreeNode root) { List<Integer> res = new ArrayList<Integer>(); inorder(root, res); return res; } public void ino
阅读全文
摘要:Map<Node, Node> map = new HashMap<>(); public Node copyRandomList(Node head) { if(head == null) return null; if(!map.containsKey(head)) { Node headNew
阅读全文
摘要:class Solution { public List<String> topKFrequent(String[] words, int k) { Map<String, Integer> map = new HashMap<>(); for(String word: words) map.put
阅读全文
摘要:private int capacity = 16; private int[] container; private boolean[] table; public MyHashMap() { this.container = new int[capacity]; this.table = new
阅读全文
摘要:public int[] dailyTemperatures(int[] temperatures) { int len = temperatures.length; LinkedList<Integer>[] table = new LinkedList[101]; for(int i = 30;
阅读全文
摘要:public int lengthOfLongestSubstring(String s) { // 开一个hashmap来维护情况,进行一个N*N的搜索 Map<Character, Boolean> map; int len = s.length(); if(len == 0) return 0
阅读全文