力扣刷题Hot100
- 73. 矩阵置零 - 力扣(LeetCode)
- 54. 螺旋矩阵 - 力扣(LeetCode)
- 48. 旋转图像 - 力扣(LeetCode)
- 240. 搜索二维矩阵 II - 力扣(LeetCode)
- 160. 相交链表 - 力扣(LeetCode)
- 206. 反转链表 - 力扣(LeetCode)
- 234. 回文链表 - 力扣(LeetCode)
- 141. 环形链表 - 力扣(LeetCode)
- 142. 环形链表 II - 力扣(LeetCode)
- 21. 合并两个有序链表 - 力扣(LeetCode)
矩阵置零
可以尝试模拟一些下面代码的思路,很容易就明白了。
▼java复制代码class Solution { public void setZeroes(int[][] matrix) { int m = matrix.length; int n = matrix[0].length; boolean f1 = false; boolean f2 = false; for (int i =0 ; i <m ;i++){ if (matrix[i][0] == 0){ f1 = true; } } for (int i = 0 ; i < n ; i ++){ if (matrix[0][i] == 0){ f2 =true; } } for (int i = 1; i < m ; i++){ for (int j = 1 ; j < n; j++){ if (matrix[i][j] == 0){ matrix[0][j] = matrix[i][0] = 0; } } } for (int i = 1 ; i < m; i++){ for (int j = 1; j < n ; j++){ if (matrix[i][0] == 0 || matrix[0][j] == 0){ matrix[i][j] = 0; } } } if (f1){ for (int i = 0 ; i < m ; i++){ matrix[i][0] = 0; } } if (f2){ for (int i = 0 ; i < n ; i++){ matrix[0][i] = 0; } } return; } }
螺旋矩阵
用四个指针围成一个矩形,每次便利玩一条边就移动一条指针缩小矩阵的范围。
▼java复制代码class Solution { public List<Integer> spiralOrder(int[][] matrix) { if (matrix.length == 0){ return List.of(); } int n = matrix.length; int m = matrix[0].length; int l = 0; int r = m - 1; int t = 0 ; int d = n -1; List<Integer> ans = new ArrayList<>(); while (true){ for (int i = l ; i <= r; i++) ans.add(matrix[t][i]); if ( ++ t > d) break; for (int i = t; i <= d; i++) ans.add(matrix[i][r]); if (-- r < l) break; for (int i = r ; i >= l ; i--) ans.add(matrix[d][i]); if (-- d < t) break; for (int i = d ; i >=t ;i --) ans.add(matrix[i][l]); if (++ l > r) break; } return ans; } }
旋转图像
先上下反转,再以对角线反转
▼java复制代码class Solution { public void rotate(int[][] matrix) { int n = matrix.length; for (int i = 0; i < n / 2 ; i++){ for (int j = 0; j < n; j ++){ int temp = matrix[i][j]; matrix[i][j] = matrix[n-1-i][j]; matrix[n-1-i][j] = temp; } } for (int i = 0; i < n;i ++){ for (int j = 0 ; j < i; j++){ int temp = matrix[i][j]; matrix[i][j] = matrix[j][i]; matrix[j][i] = temp; } } return; } }
搜索二维矩阵II
与搜索二维矩阵不同,这个题只保证行升序,和列升序,不能用二分,
可以模拟下面的思路,可以接上面两道题
▼java复制代码class Solution { public boolean searchMatrix(int[][] matrix, int target) { int n = matrix.length; int m = matrix[0].length; int i = 0; int j = m -1; while (i < n && j >= 0){ if (matrix[i][j] == target){ return true; } if (matrix[i][j] < target){ i ++; }else{ j --; } } return false; } }
相交链表
这种题就是记方法了,可以尝试模拟一下。
谁先走完,换一条路再走。
▼java复制代码/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */ public class Solution { public ListNode getIntersectionNode(ListNode headA, ListNode headB) { ListNode a = headA; ListNode b = headB; while (a != b){ if (a != null){ a = a.next; }else{ a = headB; } if (b != null){ b = b.next; }else{ b = headA; } } return a; } }
反转链表
板子题了,直接默写。。
▼java复制代码/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int val) { this.val = val; } * ListNode(int val, ListNode next) { this.val = val; this.next = next; } * } */ class Solution { public ListNode reverseList(ListNode head) { ListNode pre = null; ListNode cur = head; while (cur != null){ ListNode temp = cur.next; cur.next = pre; pre = cur; cur = temp; } return pre; } }
回文链表
寻找中间节点 + 反转链表
▼java复制代码/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int val) { this.val = val; } * ListNode(int val, ListNode next) { this.val = val; this.next = next; } * } */ class Solution { public boolean isPalindrome(ListNode head) { ListNode mid = midd(head); ListNode pre = reverse(mid); while (pre != null){ if (head.val != pre.val){ return false; } head = head.next; pre = pre.next; } return true; } private ListNode midd(ListNode head){ ListNode fast = head; ListNode slow = head; while (fast != null && fast.next != null){ slow = slow.next; fast = fast.next.next; } return slow; } private ListNode reverse(ListNode head){ ListNode pre = null; ListNode cur = head; while (cur != null){ ListNode temp = cur.next; cur.next = pre; pre = cur; cur = temp; } return pre; } }
环形链表
技巧题目,尝试模拟一下。
▼java复制代码/** * Definition for singly-linked list. * class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */ public class Solution { public boolean hasCycle(ListNode head) { ListNode fast = head; ListNode slow = head; while (fast != null && fast.next != null){ slow = slow.next; fast = fast.next.next; if (fast == slow){ return true; } } return false; } }
环形链表II
先找到是否有环,有的话,就再按照相交链表的思路解决
▼java复制代码/** * Definition for singly-linked list. * class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */ public class Solution { public ListNode detectCycle(ListNode head) { ListNode fast = head; ListNode slow = head; while (fast != null && fast.next != null){ fast = fast.next.next; slow = slow.next; if (fast == slow){ while (head != slow){ head = head.next; slow = slow.next; } return slow; } } return null; } }
合并两个有序链表
有序 + 指针
▼java复制代码/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int val) { this.val = val; } * ListNode(int val, ListNode next) { this.val = val; this.next = next; } * } */ class Solution { public ListNode mergeTwoLists(ListNode list1, ListNode list2) { ListNode dummy = new ListNode(); ListNode cur = dummy; while (list1 != null && list2 != null){ if (list1.val < list2.val){ cur.next = list1; list1 = list1.next; }else{ cur.next = list2; list2 = list2.next; } cur = cur.next; } cur.next = list1 != null ? list1 : list2; return dummy.next; } }
评论
问答助学
相关内容
0个评论
全部评论
点击登录,快来和大家讨论吧~
表情
图片
暂无评论
作者分享
来上海啦,有没有租房的推荐哇,在徐汇区上班,酒店太贵了🤑。
4
好久没冒泡了,力扣热题100题分享也停更好久了。
但是也没浪费这段时间,这段时间总体是玩+面试+毕设。结果总体毕设差不多了,以及拿到了游族网络的实习offer,年后入职,java和kotlin,说是有转正机会。说实话还是有点犹豫的,因为后面有春招,我怕实习冲突,毕竟也不可能说把机会全压在这一个公司。然后又想去试试,毕竟也算是个国内比较大的游戏公司了,再刷个实习经历简历试试。
唉,这个就业形势,双非仔真的很难哦,我都开始做两手准备,测开,真的我这段时间也在看这方面的知识,我后面投大厂春招的话,真的会all in测开了碰碰运气了,java做第二手中厂或者游戏公司的准备。
我不喜欢说大话(社恐bushi)也没啥大目标,毕竟自己的实力和背景在这,所以我认为这也是我看的很开的原因,有份工作就不错了。。。说实话我还是这一届学院第一个有正儿八经的符合专业方向的应届生,然后总共也没几个有实习经历,有不少都去了学校合作的培训机构学游戏和嵌入式了,然后放弃秋招,直接春招,我看不懂。我玩的好的室友也是学游戏,然后让他年后来上海游族网络投递找我玩,哈哈哈。
不知不觉又写了怎么多,大家觉得我的年后安排合理吗(边实习边春招),大家可以分享一下自己的经历让我参考参考。😜
tips:上海租房好贵哦,公司在徐汇区,有推荐的嘛?
3
泛微网络深圳三面结束,挂了。。。。麻了,聊的挺好的啊,可能是我薪资要高了???不会吧,我问过朋友的,也有可能是我说我比较介意二开,更喜欢做新项目,太操蛋了,挂了,直接拉黑,没一点反馈。。。。
算了,反正也没什么意愿,因为做的业务不喜欢。
卧槽,成都的MOKA刚刚来电话了,周三面试,实习转正岗位(这又是什么时候投的?🤣)
转正9k * 15。
兄弟们这薪资怎么说???
我先接面试试试我的技术水平吧。
2
力扣刷题Hot100
2
泛微网络实习面经
3
