随笔分类 -  哈希表

摘要: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++ 阅读全文
posted @ 2022-02-23 22:59 明卿册 阅读(20) 评论(0) 推荐(0) 编辑
摘要:public String minWindow(String s, String t) { // 穷尽每个字符,看是否含有这个子字符串 // 枚举所有子串,并放入 // 从字串出发,用双指针枚举-> Map<Character, Integer> smap = new HashMap<>(); Ma 阅读全文
posted @ 2022-02-11 22:24 明卿册 阅读(28) 评论(0) 推荐(0) 编辑
摘要:public int[] intersection(int[] nums1, int[] nums2) { Set<Integer> set1 = new HashSet<>(), set2 = new HashSet<>(); for(int a: nums1) set1.add(a); List 阅读全文
posted @ 2022-02-11 21:47 明卿册 阅读(15) 评论(0) 推荐(0) 编辑
摘要:public int[] dailyTemperatures(int[] temperatures) { int len = temperatures.length; LinkedList<Integer>[] table = new LinkedList[101]; for(int i = 30; 阅读全文
posted @ 2022-02-10 22:53 明卿册 阅读(18) 评论(0) 推荐(0) 编辑
摘要:class Solution { public boolean isAnagram(String s, String t) { if (s.length() != t.length()) { return false; } int[] table = new int[26]; for (int i 阅读全文
posted @ 2022-02-10 22:30 明卿册 阅读(20) 评论(0) 推荐(0) 编辑
摘要:public List<Integer> inorderTraversal(TreeNode root) { List<Integer> res = new ArrayList<Integer>(); inorder(root, res); return res; } public void ino 阅读全文
posted @ 2022-02-09 22:14 明卿册 阅读(13) 评论(0) 推荐(0) 编辑
摘要:Map<Node, Node> map = new HashMap<>(); public Node copyRandomList(Node head) { if(head == null) return null; if(!map.containsKey(head)) { Node headNew 阅读全文
posted @ 2022-02-09 21:56 明卿册 阅读(18) 评论(0) 推荐(0) 编辑
摘要:class Solution { public List<String> topKFrequent(String[] words, int k) { Map<String, Integer> map = new HashMap<>(); for(String word: words) map.put 阅读全文
posted @ 2022-02-08 23:18 明卿册 阅读(16) 评论(0) 推荐(0) 编辑
摘要:private int capacity = 16; private int[] container; private boolean[] table; public MyHashMap() { this.container = new int[capacity]; this.table = new 阅读全文
posted @ 2022-02-08 23:04 明卿册 阅读(22) 评论(0) 推荐(0) 编辑
摘要:public int[] dailyTemperatures(int[] temperatures) { int len = temperatures.length; LinkedList<Integer>[] table = new LinkedList[101]; for(int i = 30; 阅读全文
posted @ 2022-02-07 22:28 明卿册 阅读(15) 评论(0) 推荐(0) 编辑
摘要:public int lengthOfLongestSubstring(String s) { // 开一个hashmap来维护情况,进行一个N*N的搜索 Map<Character, Boolean> map; int len = s.length(); if(len == 0) return 0 阅读全文
posted @ 2022-02-07 22:09 明卿册 阅读(13) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示