今天值接上菜,不闲聊
今日小菜
题号:182 标题:Duplicate Emails 难度:Easy
SQL Schema
Write a SQL query to find all duplicate emails in a table named Person.
For example, your query should return the following for the above table:
Note: All emails are in lowercase.
我的SQL指令
select Email from (select Email,count(*) c from Person group by Email ) as table1 where table1.c>1
今日主菜
题号:169 标题:Majority Element 难度:Easy
Given an array nums of size n, return the majority element.
The majority element is the element that appears more than ⌊n / 2⌋ times. You may assume that the majority element always exists in the array.
Example 1:
Input: nums = [3,2,3]
Output: 3
Example 2:
Input: nums = [2,2,1,1,1,2,2]
Output: 2
Constraints:
• n == nums.length
• 1 <= n <= 5 * 104
• -231 <= nums[i] <= 231 - 1
我的程序码
import java.util.HashMap;
class Solution {
public int majorityElement(int[] nums) {
HashMap<Integer,Integer> temp = new HashMap<Integer, Integer>();
int l = nums.length,i,j,max=0,vmax=0;
//System.out.print(l);
for(i=0;i<l;i++){
if(temp.containsKey(nums[i])){
temp.replace(nums[i], temp.get(nums[i])+1) ;
}else{
temp.put(nums[i],1);
}
}
Set s =temp.keySet();
//System.out.println(temp);
for(Object key : s){
if(temp.get(key)>vmax){
max = (int)key;
vmax = temp.get(key);
//System.out.println(key + ","+temp.get(key));
}
}
return max;
}
}
逻辑
用HashMap,把出现过的值当key,次数当value,再去寻找value最大得时後,key是多少
这题花费比较久的时间
在HashMap,上次听大神(it邦可怜小菜鸟不能发文)说有这个东西(HashMap)可以用,刚好选到这一题,就来试试看了
DAY5心得
没有心得,继续去拚题目存库存去
<<: .NET Core第20天_TextAreaTagHelper的使用
标准通用标记式语言(Standard Generalized Markup Language, SG...
View的重复利用 由於每一个项目都会有一个新的View,当项目增加时,View也会越来越多导致效能...
今天要来介绍TypeScript(TS)的类别(Class), 以下几项是需要特别注意的。 使用cl...
昨天做完了会动的汉堡动画传送门 今天来开关侧边栏吧! 当然只要控制 width0 —> 100...
上一篇我们提到了Security Group(SG),这一篇我们来讲Network Access C...