春招前总结
找实习历程 从23年2月份开始找实习,刚开始挺难的,面试都约不到,后面越挫越勇,坚持到了6月,陆续拿到不少offer,面过的基本都过了,但8月跳槽了一次。 例如 ...
找实习历程 从23年2月份开始找实习,刚开始挺难的,面试都约不到,后面越挫越勇,坚持到了6月,陆续拿到不少offer,面过的基本都过了,但8月跳槽了一次。 例如 ...
前置知识填充篇: 满二叉树:深度为 k 的满二叉树在深度为 k 层也都有左右子树。 完全二叉树:深度为 k 的完全二叉树除了第 k 层节点可能没填满外,其余每层节点数都达到最大值,并且第 k 层的节点都集中在该层最左边的若干位置。 ...
232.用栈实现队列 思路:一个出栈的栈,一个入栈的栈实现一个队列,运用栈的四个 API ,在 pop 、peek 是要判断出栈的栈是否为空,为空就把入栈的栈内元素全 pop 到出栈的栈中。 ...
344. 反转字符串 1 2 3 4 5 6 7 8 9 10 class Solution { public void reverseString(char[] s) { char temp; for(int i=0;i<s.length/2;i++){ temp = s[i]; s[i] = s[s.length-1-i]; s[s.length-1-i] = temp; } } } 541. 反转字符串 II 字符串切割从第 i 位置到 k + i - 1 才是切下 k 个字符 . ...
242.有效的字母异位词 暴力哈希:map1.put(ch,++map1.get(ch))会报错,+1就不会。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 class Solution { public boolean isAnagram(String s, String t) { Map<Character,Integer> map1 = new HashMap<>(); Map<Character,Integer> map2 = new HashMap<>(); for(Character ch : s.toCharArray()){ if(map1.containsKey(ch)) map1.put(ch,map1.get(ch)+1); else map1.put(ch,1); } for(Character ch : t.toCharArray()){ if(map1.containsKey(ch)) map1.put(ch,map1.get(ch)-1); else return false; } for(Character ch : s.toCharArray()) if(map1.get(ch) != 0) return false; return true; } } 巧用数组: ...
203. 移除链表元素 思路:先处理头结点 null 或者 val ,再去处理移除节点。 注意:返回值返回 head。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 class Solution { public ListNode removeElements(ListNode head, int val) { //处理头结点为 val 或为 null while(head != null && head.val == val) head = head.next; if(head == null) return null; ListNode p = head; ListNode q = p.next; while(q != null){ if(q.val == val){ p.next = q.next; q = p.next; }else{ p = q; q = q.next; } } return head; } } 707. 设计链表 思路:先定义好 class ,然后在已有的 class 定义一个 size 和 头结点 head,然后写出 addAtIndex,其它都可以调用或者抄代码 ; ...
704. 二分查找 思路:首先把 left 、mid 、 right 都定义出来。mid 的赋值,左右指针的跳转都在循环内完成,注意要 left=mid+1,right = mid-1,不然有的用例会超时,循环条件则是 right ≥ left 不然藏在边界的 target 就查不到了。 ...
01背包 509. 斐波那契数 1 2 3 4 5 6 7 8 9 10 11 class Solution { public int fib(int n) { if(n<2) return n; int[] dp = new int [n+1]; dp[0] = 0; dp[1] = 1; for(int i=2;i<=n;i++) dp[i]=dp[i-1]+dp[i-2]; return dp[n]; } } 70.爬楼梯 思路:走第i层时,从i-1到i只有一种方法,从i-2到i也只有一种方法,所以从0到i-1到i有dp[i-1]种方法,从0到i-2到i有dp[i-2]种方法。所以从0到dp[i]有dp[i-2]+dp[i-1]种方法,所以dp[i]=dp[i-1]+dp[i-2]。其实也能转换为完全背包来做,物品分别是1,2。都可以无限次用。 ...
455.分发饼干 1 2 3 4 5 6 7 8 9 10 11 12 13 14 class Solution { public int findContentChildren(int[] g, int[] s) { Arrays.sort(g); Arrays.sort(s); int count=0; for(int i=0,j=0;i<s.length && j<g.length;i++){ if(s[i] >= g[j]){ count++; j++; } } return count; } } 376. 摆动序列 我的思路:直接改变数组比如4,3,4,5.只保留,4,3,5而把第三个4去掉,因为保留最高或者最低的那个更容易出现转折,最后保留下来的数组的长度就是返回值。不过这样坑多,可复用性差,下一次拿到题目抠细节抠到哭。 ...
77. 组合 思路:分为终止条件、单层逻辑两层。 终止条件:当长度为 k 就 new 这个 List 并 add 进去并 return。 单层逻辑:for 嵌套 add、递归、remove。 question: ...