No$Bug
No$Bug
全部文章
题解
专项练习(1)
归档
标签
去牛客网
登录
/
注册
No$Bug的博客
全部文章
/ 题解
(共11篇)
题解 | #删除一个二叉搜索树中的节点#
import java.util.*; /* * public class TreeNode { * int val = 0; * TreeNode left = null; * TreeNode right = null; * public TreeNode(int v...
Java
二叉树
排序树
2022-02-28
0
390
题解 | #最长公共前缀#
public String longestCommonPrefix (String[] strs) { // 字符串没有元素 if (strs == null || strs.length == 0) { return ""; ...
Java
2022-02-13
0
241
题解 | #删除有序链表中重复的元素-II#
首次提交成功,未优化 使用队列,元素先进,查看链表元素与队尾元素是否相同,相同时不入队,且在遇到下一个不同元素时删除队尾元素(要注意链表传入时的指向问题,要将队尾节点指向设为null) import java.util.*; /* * public class ListNode { * ...
Java
队列
链表
2021-10-24
0
345
题解 | #寻找峰值#
nums[-1] = nums[n] = -∞ 1 <= 数组长度 <= 1000 0 <= 数组元素的值 <= 1000 重新创建数组arr,第一个与最后一个元素设为-1,其它元素依次为参数数组a元素,再遍历arr数组,arr.index = [1, a.length] ...
Java
2021-09-19
0
288
题解 | #反转链表#
方式一:使用栈 栈先进后出的规则1——>2——>3出栈3——>2——>1但是1节点仍然指向着2,形成了2节点与1节点的循环,所以要使最后节点指针指向null public ListNode ReverseList(ListNode head) { if (...
2021-09-09
0
297
题解 | #判断一个链表是否为回文结构#
在比较时注意==和equals的使用 public boolean isPail (ListNode<Integer> head) { ArrayList<Integer> list = new ArrayList<>(); while (hea...
2021-09-08
0
259
题解 | #链表中倒数最后k个结点#
public ListNode FindKthToTail (ListNode pHead, int k) { // write code here if (pHead == null || k < 1) { return null; ...
2021-08-24
0
306
题解 | #删除链表的倒数第n个节点#
public ListNode removeNthFromEnd (ListNode head, int n) { // write code here // 节点个数 int count = 0; // 当前节点 Li...
2021-08-22
0
325
题解 | #删除有序链表中重复的元素-I#
public ListNode deleteDuplicates (ListNode head) { // 创建set集合,集合内元素不重复 HashSet<Integer> set = new HashSet<>(); // ...
2021-08-21
0
318
题解 | #用两个栈实现队列#
/** * 实现队列 */ Stack<Integer> stack1 = new Stack<Integer>(); /** * 临时存储队列的元素 */ Stack<Integer> stack2 = new Stack<Integer>(); ...
2021-08-21
0
252
首页
上一页
1
2
下一页
末页