3. 无重复字符的最长子串
class Solution {
public int lengthOfLongestSubstring(String s) {
if(s.length()==0) return 0;
HashMap<Character,Integer> map = new HashMap<>();
int left = 0;
int max = 0;//记录最长子串长度
for(int i = 0;i<s.length();i++){
if(map.containsKey(s.charAt(i))){
left = Math.max(left,map.get(s.charAt(i))+1);
}
map.put(s.charAt(i),i);
max = Math.max(max,i-left+1);
}
return max;
}
}
面试题14- II. 剪绳子 II
class Solution {
public int cuttingRope(int n) {
if(n==2){
return 1;
}
if(n==3){
return 2;
}
long res = 1;
while(n>4){
res *= 3;
res = res % 1000000007;
n = n - 3;
}
return (int)(res*n % 1000000007);
}
}
你知道的越多,你不知道的越多。