剑指offer刷题Java知识点笔记

Java:

char []ch = s.toCharArray();
int len=ch.length;等价于int len=s.length();
HashSet<Integer> set=new HashSet<>(); //set.contains(key)+set.add(key)+set.remove(key)
HashMap<Integer,Integer> map=new HashMap<>(); 
HashMap<Character,Integer>mp=new HashMap<>();
map.get(key)//获取+map.put()//插入,无则追加有则更改+map.containsKey(key)//判断是否含有key+
map.remove(key)//删除key对应的value+map.keySet()//显示map所有的key
if(mp.get(num)==null) mp.put(num,1);
return new int[]{nums[i],nums[j]};     return new int[]{}; //==return new int[0];
StringBuilder sb=new StringBuilder();
sb.append();
return sb.toString();  //把sb转换为String
ArrayList<Integer> list = new ArrayList<>(); 
list.add(i)+list.get(i)+list.size()+list.remove();
ArrayList是一个动态数组,数组时更优
List<Integer> list=new LinkedList<>();
list.add(i)+list.contains(i)+list.size()+list.get()+list.remove();
LinkedList与ArrayList一样实现List接口,不同之处是采用的存储结构不同,
ArrayList的数据结构为线性表,而LinkedList数据结构是链表,LinkedList类每个结点用内部类Node表示。
List<List<Integer>> res=new ArrayList<>();
LinkedList<List<Integer>> res=new LinkedList<>();
LinkedList<Integer> path=new LinkedList<>(); path.removeLast();
Arrays.sort(nums);+ Arrays.sort(nums,c);+Arrays.sort(nums,0,n);//nums是一个数组
char []words=word.toCharArray();
boolean[][] visited = new boolean[m][n];
return (int)Math.pow(3,a)  //Math.pow()的返回值类型是double
链表和树的问题,往往可以用递归的解法
ListNode dummy = new ListNode(0);//创建一个哑节点
if(matrix.length==0) return new int[0];   //返回值为数组
int []res=new int[(r+1)*(b+1)];
if(matrix.length==0) return new LinkedList<>(); //返回值为List
List<Integer> list=new LinkedList<>();
Stack<Integer> stack=new Stack();stack.peek()+stack.push()+stack.empty()+stack.pop()
String[] str=new String[nums.length];   //nums为数组
str[i]=String.valueOf(nums[i]); //由基本数据类型转为String
char[]arr=String.valueOf(num).toCharArray();//先将int num转为String,再转为char数组。
int [][]dp=new int[nums.length][nums[0].length]; 
String s;   
s.charAt(index) //String类的charAt() 方法用于返回指定索引处的字符。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值