![](https://img-blog.csdnimg.cn/20201014180756919.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
力扣简单题目哈希表部分
qch60925
这个作者很懒,什么都没留下…
展开
-
496-下一个更大元素
496-下一个更大元素 输入: nums1 = [4,1,2], nums2 = [1,3,4,2]. 输出: [-1,3,-1] 哈希表做法, class Solution { public int[] nextGreaterElement(int[] nums1, int[] nums2) { HashMap<Integer,Integer> hs=new HashMap<>(); int[]res=new int[nums1.length原创 2021-02-07 23:25:59 · 53 阅读 · 0 评论 -
1-两数字之和Target(HashMap)
1两数字之和为Target,找两个数字 class Solution { public int[] twoSum(int[] nums, int target) { HashMap<Integer,Integer> map=new HashMap<>(); for(int i=0;i<nums.length;i++){ int dec = target-nums[i]; if(map.con原创 2021-01-29 21:32:30 · 243 阅读 · 0 评论 -
169-找出大于n/2的元素HashMap
169-找出大于n/2的元素 import java.util.*; class Solution { public int majorityElement(int[] nums) { HashMap<Integer,Integer> map = new HashMap<>(); int index=0; for(Integer i:nums){ if(map.containsKey(i)){原创 2021-01-29 21:25:45 · 72 阅读 · 0 评论 -
202-快乐数(HashSet)
力扣题目:202题 1.解题思路: 对n按位拆分求和; set集合进行判断sum有无出现过; 2.代码 class Solution { public int getSum(int n){ int sum = 0; while(n>0){ sum+=(n%10)*(n%10); n=n/10; } return sum; } public boolean isH原创 2021-01-29 16:45:45 · 86 阅读 · 0 评论