摘要: 8.2:双向链表实现栈 底层都是双链表调整 1 public static class Node<T> { 2 public T value; 3 public Node<T> last; 4 public Node<T> next; 5 6 public Node(T data) { 7 valu 阅读全文
posted @ 2022-05-08 10:56 yzmarcus 阅读(210) 评论(0) 推荐(0) 编辑
摘要: 8.1:双向链表实现双端队列 双端队列,玩的head 和tail指针 底层都是双链表调整 1、双向链表 节点1 public static class Node<T> { 2 public T value; 3 public Node<T> last; 4 public Node<T> next; 阅读全文
posted @ 2022-05-08 10:50 yzmarcus 阅读(34) 评论(0) 推荐(0) 编辑
摘要: 8:栈和队列 逻辑概念: 栈:数据先进后出,犹如弹匣 队列:数据先进先出,好似排队 栈和队列的实现: 1、双向链表实现 2、数组实现 阅读全文
posted @ 2022-05-08 10:41 yzmarcus 阅读(19) 评论(0) 推荐(0) 编辑
摘要: 7.2:链表删除给定值 1 // head = removeValue(head, 2); 2 public static Node removeValue(Node head, int num) { 3 // head来到第一个不需要删的位置 4 while (head != null) { 5 阅读全文
posted @ 2022-05-06 18:43 yzmarcus 阅读(34) 评论(0) 推荐(0) 编辑
摘要: 7.1:链表反转 链表反转注意:返回头部节点。 单链表的反转 // head // a -> b -> c -> null // c -> b -> a -> null public static Node reverseLinkedList(Node head) { Node pre = null 阅读全文
posted @ 2022-05-05 20:05 yzmarcus 阅读(18) 评论(0) 推荐(0) 编辑
摘要: 7:链表结构 单向链表节点结构 public static class Node { public T value; public Node next; public Node(T data) { value = data; } } 双向链表 public static class Node<T> 阅读全文
posted @ 2022-05-05 20:03 yzmarcus 阅读(17) 评论(0) 推荐(0) 编辑
摘要: 6.4: 一个数组中有一种数出现K次,其它数都出现了M次,M > 1, K < M,找到出现K次的数,要求,额外空间复杂度O(1),时间复杂度O(N) 例如:arr[] 其中2出现K次,9出现M次,M != 1,M > 1, K < M。 1 // 请保证arr中,只有一种数出现了K次,其它数都出现 阅读全文
posted @ 2022-05-05 15:19 yzmarcus 阅读(72) 评论(0) 推荐(0) 编辑
摘要: 6.3:一个数组中有两种数出现了奇数次,其它数出现了偶数次,怎么找到并打印这两种数 两种数出现奇数次,其它偶数次 1、用eor = 0去逐个异或,最后一定是 eor = a^b, a和b是这个两个出现奇数次的数。偶数次异或为0。 2、a != b, eor != 0; eor的binary一定有1, 阅读全文
posted @ 2022-05-03 13:49 yzmarcus 阅读(140) 评论(0) 推荐(0) 编辑
摘要: 6.2:怎么把一个int类型的数,提取出最右侧的1来 int a = 01101110010000 ?处理后 int ans =00000000010000,返回。 a&((~a)+1) == a&(-a) int a = 01101110010000 ; ~a = 10010001101111 & 阅读全文
posted @ 2022-05-03 13:34 yzmarcus 阅读(92) 评论(0) 推荐(0) 编辑
摘要: 6.1:一个数组中有一种数出现了奇数次,其它数出现了偶数次,怎么找到并打印这种数? 方法一:哈希表统计词频,找到奇数次的那个数 方法二:异或运算 [4,3,4,2,4,3,1,2,1,1,1,3,3],其中1111,22,3333,444 eor = 0 去异或1111,22,3333,444 得到 阅读全文
posted @ 2022-05-03 13:21 yzmarcus 阅读(21) 评论(0) 推荐(0) 编辑