题目描述:
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.
According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes v and w ...
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.
According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes v and w ...
Given a linked list, return the node where the cycle begins. If there is no cycle, return null.
Follow up:
Can you solve it without using extra space?
给定一个链表,返回循环的起始节点。如果没有环,则返回空。
进一步思考:
你可以在不使用额外空间的条件下完成题目吗?
参考LeetCode Discuss(https ...
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?
给定一个单链表,判断它是否是回文。
进一步思考:
你可以在O(n)时间复杂度和O(1)空间复杂度完成吗?
1). 使用快慢指针寻找链表中点
2). 将链表的后半部分就地逆置 ...
Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n.
For example:
Given n = 13,
Return 6, because digit 1 occurred in the following numbers: 1, 10 ...
Implement the following operations of a queue using stacks.