leetcode二刷
却顾所来径
当你老了,回顾一生,就会发觉:什么时候出国读书、什么时候决定做第一份职业、何时选定了对象而恋爱、什么时候结婚,其实都是命运的巨变。只是当时站在三岔路口,眼见风云千樯,你作出抉择的那一日,在日记上,相当的沉闷和平凡,当时还以为是生命中普通的一天。
展开
-
leetcode 257. 二叉树的所有路径(java)
给定一个二叉树,返回所有从根节点到叶子节点的路径。 说明:叶子节点是指没有子节点的节点。 示例: 输入: 1 / \ 2 3 \ 5 输出: ["1->2->5", "1->3"] 解释: 所有根节点到叶子节点的路径为: 1->2->5, 1->3 思路: 1.root为空,易知,只有一种情况,那就是题目所给是空树 ...翻译 2019-03-13 23:03:08 · 1585 阅读 · 0 评论 -
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 thedefinition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes p...翻译 2019-04-12 19:47:27 · 132 阅读 · 0 评论 -
leetcode 102. Binary Tree Level Order Traversal(层次遍历)
Given a binary tree, return thelevel ordertraversal of its nodes' values. (ie, from left to right, level by level). For example: Given binary tree[3,9,20,null,null,15,7], 3 / \ 9 20 ...翻译 2019-04-12 18:28:17 · 68 阅读 · 0 评论 -
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 the ...翻译 2019-04-02 19:42:18 · 92 阅读 · 0 评论 -
leetcode 24. Swap Nodes in Pairs
Given alinked list, swap every two adjacent nodes and return its head. You maynotmodify the values in the list's nodes, only nodes itself may be changed. Example: Given 1->2->3->4, ...翻译 2019-04-02 19:02:20 · 74 阅读 · 0 评论 -
leetcode 160. Intersection of Two Linked Lists
Write a program to find the node at which the intersection of two singly linked lists begins. For example, the following two linked lists: begin to intersect at node c1. Example 1: Input: ...翻译 2019-03-26 19:29:01 · 76 阅读 · 0 评论 -
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 p...翻译 2019-03-30 19:37:09 · 111 阅读 · 0 评论 -
leetcode 725. Split Linked List in Parts
Given a (singly) linked list with head noderoot, write a function to split the linked list intokconsecutive linked list "parts". The length of each part should be as equal as possible: no two part...翻译 2019-03-30 18:52:12 · 114 阅读 · 0 评论 -
leetcode 876. Middle of the Linked List
Given a non-empty, singlylinked list with head nodehead, returnamiddle node of linked list. If there are two middle nodes, return the second middle node. Example 1: Input: [1,2,3,4,5] Outpu...翻译 2019-03-23 20:22:16 · 95 阅读 · 0 评论 -
leetcode 206. Reverse Linked List
Reverse a singly linked list. Example: Input: 1->2->3->4->5->NULL Output: 5->4->3->2->1->NULL Follow up: A linked list can be reversed either iteratively or recursi...翻译 2019-03-23 18:26:04 · 90 阅读 · 0 评论 -
leetcode 445. Add Two Numbers II
You are given twonon-emptylinked 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 return i...翻译 2019-03-29 20:17:29 · 76 阅读 · 0 评论 -
leetcode 234. Palindrome Linked List(回文链表)
Given a singly linked list, determine if it is a palindrome. Example 1: Input: 1->2 Output: false Example 2: Input: 1->2->2->1 Output: true Follow up: Could you do it in O(n) time a...翻译 2019-03-25 19:04:45 · 79 阅读 · 0 评论 -
leetcode 141. Linked List Cycle(链表是否存在环)
Given a linked list, determine if it has a cycle in it. To represent a cycle in the given linked list, we use an integerposwhich represents the position (0-indexed)in the linked list where tail co...翻译 2019-03-25 18:06:36 · 177 阅读 · 0 评论 -
leetcode 21. Merge Two Sorted Lists
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. Example: Input: 1->2->4, 1->3->4 Output: 1-...翻译 2019-03-24 22:00:09 · 85 阅读 · 0 评论 -
leetcode 236. 二叉树的最近公共祖先(java)
Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According to thedefinition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes p...翻译 2019-03-12 20:14:07 · 691 阅读 · 0 评论 -
leetcode 112. 路径总和
给定一个二叉树和一个目标和,判断该树中是否存在根节点到叶子节点的路径,这条路径上所有节点值相加等于目标和。 说明:叶子节点是指没有子节点的节点。 示例: 给定如下二叉树,以及目标和sum = 22, 5 / \ 4 8 / / \ 11 13 4 ...翻译 2019-03-12 18:41:38 · 175 阅读 · 0 评论 -
leetcode 543. Diameter of Binary Tree
Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of thelongestpath between any two nodes in a tree. This path may or may no...翻译 2019-04-17 00:10:37 · 67 阅读 · 0 评论