![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
dreamsyoung
这个作者很懒,什么都没留下…
展开
-
Remove Nth Node From End of List
Given a linked list, remove the nth node from the end of list and return its head. For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the原创 2015-06-10 16:36:42 · 567 阅读 · 0 评论 -
Maximum Depth of Binary Tree Java
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. /** * Definition for a binary tre原创 2015-07-08 11:40:36 · 388 阅读 · 0 评论 -
Minimum Depth of Binary Tree Java
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. /** * Definition for a binary tre原创 2015-07-08 11:43:10 · 384 阅读 · 0 评论 -
Reverse Linked List(反转链表)
Reverse a singly linked list. 解题思路:用两个变量prev,temp分别表示当前结点(head)的前一个和后一个结点,画下图就可以知道了 上代码: public class Solution { public ListNode reverseList(ListNode head) { ListNode prev = null;原创 2015-06-15 16:59:04 · 608 阅读 · 0 评论 -
Number of 1 Bits
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight). For example, the 32-bit integer ’11' has binary representation 000000原创 2015-07-06 15:31:46 · 467 阅读 · 0 评论 -
Binary Tree Preorder Traversal Java版本
二叉树先序遍历 思路: 不使用递归前序遍历,可以借助栈的帮助实现。对于一个特定节点,前序遍历顺序为: 根,左,右。所以入栈顺序为 右,左,根。由于根节点的遍历和展开(研究其右节点和左 节点)是同时的,所以根节点出栈的同时即可加入遍历结果中,然后研究其右节点和左节点,如果不为空即可入栈。 /** * Definition for a binary tree node. * pu原创 2015-07-06 16:57:45 · 386 阅读 · 0 评论