0%
1 自定义排序
class Solution { public String largestNumber(int[] nums) { int n=nums.length; Integer[] arr=new Integer[n]; for(int i=0;i<n;i++){ arr[i]=nums[i]; } Arrays.sort(arr,(x,y)->{ long sx=10,sy=10; while(sx<=x){ sx=sx*10; } while(sy<=y){sy=sy*10;}
return (int) (y*sx+x-(x*sy+y)); });
if(arr[0]==0){ return "0"; } StringBuilder sb = new StringBuilder(); for(int num:arr){ sb.append(num); } return sb.toString(); } }
|
2 数组
List<int[]>[] g=new ArrayList[n]; Arrays.setAll(g,i->new ArrayList<>());
int[][] points; Arrays.sort(points,(a,b)->Integer.compare(a[0],b[0]));
int[][] grid; int m=grid.length,n=grid[0].length; int[] row=new int[m]; int[] col=new int[n];
int[] nums=new int[n];
int n=nums.length; Arrays.fill(nums,1);
return new int[]{-1,-1};
int[] nums; Arrays.sort(nums);
|
操作 |
说明 |
nums.set(index,last) |
设置Index下标元素值 |
nums.remove(index) |
|
nums.size() |
|
|
|
|
|
|
|
3 List
List<List<Integer>> ans=new ArrayList<List<Integer>>();
|
4 String
String s;
s.length();
s.charAt(index);
StringBuilder s=new StringBuilder(); s.deleteCharAt(s.length()-1);
|
5 Map
操作 |
说明 |
s.containsKey(val) |
|
s.remove(key) |
|
s.get(key) |
|
Map<Character, Character> pairs = new HashMap<Character, Character>() {{ put(')', '('); put(']', '['); put('}', '{'); }};
|
6 Set
操作 |
说明 |
Set<Character> s=new HashSet() |
|
s.contains(ch) |
|
s.add(ch) |
s中包含ch,返回false |
s.remove(ch) |
|
7 Stack
Deque<Character> stack=new LinkedList<Character>(); stack.isEmpty() stack.peek() stack.pop() stack.push(ch)
|