更新 Solution.java
parent
955e0e3d05
commit
6571eb45d2
|
|
@ -8,7 +8,7 @@ import java.util.Set;
|
|||
public class Solution {
|
||||
|
||||
//给定一个字符串 s ,找出其中不含有重复字符的 最长子串 的长度。
|
||||
public int lengthOfLongestSubstring(String s) {
|
||||
public static int lengthOfLongestSubstring(String s) {
|
||||
// 哈希集合,记录每个字符是否出现过
|
||||
Set<Character> occ = new HashSet<Character>();
|
||||
int n = s.length();
|
||||
|
|
@ -52,7 +52,7 @@ public class Solution {
|
|||
|
||||
|
||||
//哈希映射算法(Hash Mapping Algorithm)用于找出一个数组中的众数(majority element)
|
||||
public int majorityElement(int[] nums) {
|
||||
public static int majorityElement(int[] nums) {
|
||||
Map<Integer, Integer> map = new HashMap<>();
|
||||
// maxNum 表示元素,maxCount 表示元素出现的次数
|
||||
int maxNum = 0, maxCount = 0;
|
||||
|
|
|
|||
Loading…
Reference in New Issue