十六进制转换十进制 ####################
//0x62A3 =》 ((6*16+2)*16+'A')*16+3
List初始化 ####################
List list = Arrays.asList("W", "S", "A", "D");
特殊 ####################
Integer.MAX_VALUE
Integer.MAX_VALUE
ascii码转字符 ####################
int i='a';
System.out.print(i);
// 获取a ascii码
System.out.println("a".codePointAt(0));
s[i].charAt(0) - 'A'
输入 ####################
Scanner sc = new Scanner(System.in);
sc.nextInt();
sc.nextLine();
字符串操作 ####################
String s[] = str.split("");
s[i].charAt(0)
str.length()
int []nums={100,2,3,4,5,78,34,100,45,33,9,0,0,1,3,4,5};
Arrays.sort(nums);
List<Integer> list = new ArrayList<Integer>();
Collections.sort(list, Collections.reverseOrder());降序
Collections.sort(list); 升序
String[] str = new String[num];
String[] str ={"A","B"};
Arrays.sort(str); 升序
Arrays.sort(arr,Collections.reverseOrder()); 降序
List<String> strList = new ArrayList<>();
String[] toBeStored = strList.toArray(new String[strList.size()]);
//截取0~2 不包括2 得0,1
str.substring(0,2)
//a=b=0 a>b=1 a<b=-1
a.compareTo(b)
//以f结尾true
a.endsWith("f")
a.startsWith("f")
//字符串第一次出现C位置
String a = "abcdcefg";
a.indexOf("c") //2
//正则表达式
a.matches(regex)
String a = "abcdcefg";
a.lastIndexOf("c") //4
a.lastIndexOf("c",3) //2 索引0,1,2,3 移动到d,d前搜索结果为2
//方法当且仅当此String表示与StringBuffer中指定的字符序列相同时
a.contentEquals(cs)
a.replace('old','new')
a.replaceAll('old','new')
a.toLowerCase();
a.toUpperCase()
char[] Str1 = {'h', 'e', 'l', 'l', 'o', ' ', 'r', 'u', 'n', 'o', 'o', 'b'};
String Str2 = "";
Str2 = Str2.copyValueOf( Str1 );
//Hello,World,2019
List<String> words = Arrays.asList(new String[] { "Hello", "World", "2019" });
String msg = String.join(",", words);
//ca
String.format("C%s", "A")
//CharSequence cs hashcode ?
Map ####################
Set<Entry<String,Integer>>mapEntries=hs.entrySet();
List<Entry<String,Integer>>aList=new LinkedList<Entry<String,Integer>>(mapEntries);
//根据value排序
Collections.sort(aList, new Comparator<Map.Entry<String, Integer>>() {
public int compare(Map.Entry<String, Integer
mao轩:
Map ####################
Set<Entry<String,Integer>>mapEntries=hs.entrySet();
List<Entry<String,Integer>>aList=new LinkedList<Entry<String,Integer>>(mapEntries);
//根据value排序
Collections.sort(aList, new Comparator<Map.Entry<String, Integer>>() {
public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
return (o1.getValue() - o2.getValue());
}
});
HashMap<String, Integer> hs = new HashMap<>();
for (Map.Entry<String, Integer> m : hs.entrySet()) {
System.out.println(m.getKey() + " " + m.getValue());
}
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
for(Map.Entry<Integer, Integer> entry : map.entrySet()){
System.out.println("key = " + entry.getKey() + ", value = " + entry.getValue())
}
Map<Integer,String> map =new HashMap<Integer,String>();
map.put(1, "xiao");
map.put(2, "chao");
map.put(3, "shang");
map.put(4, "xue");
//方法一
for(Map.Entry<Integer,String> entry : map.entrySet()) {
System.out.println("方法一:key ="+entry.getKey()+"---value="+entry.getValue());
}
//方法二
for(Integer key:map.keySet()) {
System.out.println("方法二:key = "+key);
}
for(String value:map.values()) {
System.out.println("方法二:value = "+value);
}
//方法三
Iterator<Map.Entry<Integer,String>> entries = map.entrySet().iterator();
while(entries.hasNext()) {
Map.Entry<Integer,String> entry = entries.next();
System.out.println("方法三:key = "+entry.getKey()+"--value="+entry.getValue());
}
//方法四
for(Integer key:map.keySet()) {
String value = map.get(key);
System.out.println("方法四:Key = " + key + ", Value = " + value);
}
}
贪心算法:
KMP算法
回溯算法
二叉树
链表
数组:二分查找法
1.定义left和right,一个起始,一个结尾
2.通过while(left <=right)循坏
3.里面定义mid参数,mid=right-left/2
4.判断
if(s[mid] < s[right])
else if (s[mid] > s[left])
else (s[mid] == s[right])
回溯算法:组合问题,切割问题,子集问题,排列问题,棋盘问题
一般写法:
1.先定义统计好输入需要字符的个数
2.进行递归,参数一般为map字符统计集,存储单元new String[n](储存单元结果集不能是引用类型),new chr[n],left,right
3.递归方法内主要
1.树形结构有始有终,一开始要判断left==right 为true添加结果集和return
2.进行对map集合for遍历,方法内判断边界,特殊条件和参数字符数量消耗边界值
3. 当前2条件满足后,进行深度遍历,map对应字符抽取,数量减一,再次进入递归,参数为map剩余字符结果集,存储单元,left+1,right
4、回溯,map剩余字符结果集把上面消耗的元素重新增加,为for其他参数遍历做准备