//链表做的stack java版: import edu.princeton.cs.algs4.*; import java.util.Iterator; public class Stack<Item> implements Iterable<Item> { private Node first ...
分类:
其他好文 时间:
2018-04-30 20:01:36
阅读次数:
209
蓄水池抽样——《编程珠玑》读书笔记 382. Linked List Random Node 398. Random Pick Index 蓄水池抽样——《编程珠玑》读书笔记 382. Linked List Random Node 398. Random Pick Index 问题:如何随机从n个 ...
分类:
编程语言 时间:
2018-04-30 13:37:33
阅读次数:
283
1. Convert Sorted List to Binary Search Tree Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced ...
分类:
其他好文 时间:
2018-04-23 15:41:49
阅读次数:
161
Given a singly linked list, determine if it is a palindrome. Follow up: Could you do it in O(n) time and O(1) space? 思路: 把链表一分为二。把右边的一半翻转,再逐个比对左右的链表就可 ...
分类:
其他好文 时间:
2018-04-21 17:48:41
阅读次数:
136
给定一个单链表,随机选择链表的一个节点,并返回相应的节点值。保证每个节点被选的概率一样。进阶:如果链表十分大且长度未知,如何解决这个问题?你能否使用常数级空间复杂度实现?示例:// 初始化一个单链表 [1,2,3].ListNode head = new ListNode(1);head.next ...
分类:
其他好文 时间:
2018-04-15 21:07:38
阅读次数:
240
Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the ...
分类:
其他好文 时间:
2018-04-14 18:07:07
阅读次数:
125
请检查一个链表是否为回文链表。 进阶:你能在 O(n) 的时间和 O(1) 的额外空间中做到吗? 详见:https://leetcode.com/problems/palindrome-linked-list/description/ 方法一: 方法二: 参考:https://www.cnblogs ...
分类:
其他好文 时间:
2018-04-09 14:57:02
阅读次数:
146
系统整理了一下有关Java的面试题,包括基础篇,javaweb篇,框架篇,数据库篇,多线程篇,并发篇,算法篇等等,陆续更新中。其他方面如前端后端等等的面试题也在整理中,都会有的。 注:文末有福利!pdf版本可在文章末尾获取 1、ArrayList和Vector的区别 这两个类都实现了List接口(L ...
分类:
编程语言 时间:
2018-04-08 14:28:10
阅读次数:
195
【题目描述】 Implement an algorithm to delete a node in the middle of a singly linked list, given only access to that node. 给定一个单链表中的一个等待被删除的节点(非表头或表尾)。请在在O ...
分类:
其他好文 时间:
2018-04-07 11:22:23
阅读次数:
146
题目描述: Given a sorted linked list, delete all duplicates such that each element appear only once. For example,Given 1->1->2, return 1->2.Given 1->1->2- ...
分类:
其他好文 时间:
2018-04-06 15:21:31
阅读次数:
150