// 赋值int a;int[] ar =newint[100];
BigInteger x, y, ans;
BigInteger tmp =newBigInteger(str);// String 类型转换为BigInteger(BigDecimal)
x = BigInteger.valueOf(a);// int(double)类型转换为BigInteger(BigDecimal)// BigInteger/BigDecimal 常用方法(所有方法均为1个参数)
ans = x.add(y);// 加
ans = x.subtract(y)// 减
ans = x.multiply(y);// 乘
ans = x.divide(y);// 整除
ans = x.pow(int exponent);// 幂
ans = x.abs(y);// 绝对值if(x.compareTo(y)==0)// 比较// 仅BigInteger:
ans = x.and(y);// 求与
ans = x.or(y);// 求或
ans = x.not(y);// 求反
ans = x.xor(y);// 求异或
ans = x.mod(y);// 取模
ans = x.gcd(y)// 最大公约数
// leetcode 3. Longest Substring Without Repeating CharacterspublicclassSolution{publicintlengthOfLongestSubstring(String s){int n = s.length(), ans =0;
Map<Character, Integer> map =newHashMap<>();// current index of character// try to extend the range [i, j]for(int j =0, i =0; j < n; j++){if(map.containsKey(s.charAt(j))){// containsKey
i = Math.max(map.get(s.charAt(j)), i);// get}
ans = Math.max(ans, j - i +1);
map.put(s.charAt(j), j +1);// put}return ans;}}
11. Set
// leetcode 3. Longest Substring Without Repeating CharacterspublicclassSolution{publicintlengthOfLongestSubstring(String s){int n = s.length();int ans =0;for(int i =0; i < n; i++)for(int j = i +1; j <= n; j++)if(allUnique(s, i, j)) ans = Math.max(ans, j - i);return ans;}publicbooleanallUnique(String s,int start,int end){
Set<Character> set =newHashSet<>();// 定义for(int i = start; i < end; i++){
Character ch = s.charAt(i);if(set.contains(ch))returnfalse;// contains
set.add(ch);// add}returntrue;}}