自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

LoveCodeLiu

天行健,君子以自强不息。

  • 博客(16)
  • 问答 (1)
  • 收藏
  • 关注

原创 【LeetCode】【236】【Lowest Common Ancestor of a Binary Tree】

题目:Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes ...

2018-10-09 14:37:11 120

翻译 【LeetCode】【222】【Count Complete Tree Nodes】

题目:Given a complete binary tree, count the number of nodes.解题思路:完全树的定义就不用我说了吧,本人想了很多种方法都超时。。。。借鉴一下LeetCode大神的方法:https://leetcode.com/problems/count-complete-tree-nodes/discuss/61958/Concise-Java-solu...

2018-10-05 21:20:51 141

原创 【LeetCode】【129】【Sum Root to Leaf Numbers】

题目:Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number 123.Find the tot...

2018-10-05 20:38:08 160

转载 【leetcode】【863】【All Nodes Distance K in Binary Tree】

题目:We are given a binary tree (with root node root), a target node, and an integer value K.Return a list of the values of all nodes that have a distance K from the target node. The answer can be ret...

2018-10-02 10:13:26 217

转载 【LeetCode】【94】【Binary Tree Inorder Traversal】

题目:Given a binary tree, return the inorder traversal of its nodes’ values.解题思路:树的非递归遍历,先序,中序,后序都用栈,层序用队列。建议最好写非递归的代码:class ListNode { int val; ListNode next; ListNode(int x) { v...

2018-10-02 08:55:55 143

原创 【LeetCode】【24】【Swap Nodes in Pairs】

题目:Given a linked list, swap every two adjacent nodes and return its head.解题思路:这个题还是比较容易的吧,两个一组把后面的插入到前面的链表中。注意不要断链。代码:class ListNode { int val; ListNode next; ListNode(int x) { ...

2018-10-01 10:14:08 96

原创 【LeetCode】【61】【Rotate List】

题目:Given a linked list, rotate the list to the right by k places, where k is non-negative.解题思路:所谓链表循环右移就是头插法,但是这个题你要是一个一个得去做会导致超时,所以我们把需要移动的节点看成是一起的,以start开始,tail结束。代码:class ListNode { int val;...

2018-10-01 10:00:56 137

原创 【LeetCode】【86】【Partition List】【链表】

题目:Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of the nodes in each of...

2018-10-01 09:02:46 174

翻译 【LeetCode】【109】【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 BST.For this problem, a height-balanced binary tree is defined as a binary tree in which th...

2018-09-28 10:55:02 118

原创 【LeetCode】【445】【Add Two Numbers II】【链表】

题目:You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contain a single digit. Add the two numbers and retur...

2018-09-28 09:37:35 218

原创 【LeetCode】【147】【Insertion Sort List】【链表】

题目:Sort a linked list using insertion sort.解题思路:链表的插入排序,基本原理跟顺序表一样的,仔细理解就好。dummyNode是真的好用代码: class ListNode { int val; ListNode next; ListNode(int x) { val = x; } } public ...

2018-09-28 08:47:21 169

翻译 【LeetCode】【148】【Sort List】【链表】

题目:Sort a linked list in O(n log n) time using constant space complexity.借鉴于:https://leetcode.com/problems/sort-list/discuss/46714/Java-merge-sort-solution解题思路:链表的归并排序还是值得好好研究一下的,跟顺序表的原理一样,注意设置好递归的结...

2018-09-28 08:28:15 182

原创 【LeetCode】【19】【Remove Nth Node From End of List】【链表】

题目:Given a linked list, remove the n-th node from the end of list and return its head.解题思路:题目很简单,移除链表中的倒数第n个节点,先正序算一下链表长度,然后再找出第n个。善用dummy节点,可以用来删除第一个。代码: class ListNode { int val; Lis...

2018-09-27 16:05:22 109

原创 【LeetCode】【138】【Copy List with Random Pointer】【链表】

题目:A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list.解题思路:复杂链表的复制问题,每一个节点都有两个指针,一个指向下一...

2018-09-27 15:34:55 135

翻译 【LeetCode】【328】【Odd Even Linked List】【链表】

题目: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 value in the nodes.You should try to do it in...

2018-09-27 09:59:34 114

翻译 【LeetCode】【2】【链表】

题目:You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and retur...

2018-09-27 09:25:32 118

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除