自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(32)
  • 收藏
  • 关注

原创 Tree——No.965 Univalued Binary Tree

Problem:A binary tree is univalued if every node in the tree has the same value.Return true if and only if the given tree is univalued.Explanation:判断一棵树中所有结点的值是否相同。My Thinking:使用前序遍历,将每个结点...

2019-03-31 16:05:47 88

原创 Tree——No.987 Vertical Order Traversal of a Binary Tree

Problem:Given a binary tree, return the vertical order traversal of its nodes values.For each node at position (X, Y), its left and right children respectively will be at positions (X-1, Y-1) and ...

2019-03-31 16:04:41 95

原创 String——No.17 Letter Combinations of a Phone Number

Problem:Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone butto...

2019-03-30 17:23:17 107

原创 Tree——No.572 Subtree of Another Tree

Problem:Given two non-empty binary trees s and t, check whether tree t has exactly the same structure and node values with a subtree of s.A subtree of s is a tree consists of a node in s and all o...

2019-03-30 17:22:22 116

原创 Tree——No.654 Maximum Binary Tree

No.654 Maximum Binary TreeProblem:Given an integer array with no duplicates. A maximum tree building on this array is defined as follow:The root is the maximum number in the array.The left sub...

2019-03-29 22:31:34 82

原创 Tree——No.429 N-ary Tree Level Order Traversal

No.429 N-ary Tree Level Order TraversalProblem:Given an n-ary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).Explanation:对n叉树进行层序遍历。My ...

2019-03-27 20:27:41 125

原创 Tree——No.872 Leaf-Similar Trees

Problem:Consider all the leaves of a binary tree. From left to right order, the values of those leaves form a leaf value sequence.Explanation:判断两个二叉树是否叶子结点序列相同My Thinking:使用递归,将每个叶子结点存入li...

2019-03-27 20:26:47 229

原创 Tree——No.437 Path Sum III

No.437 Path Sum IIIProblem:You are given a binary tree in which each node contains an integer value.Find the number of paths that sum to a given value.The path does not need to start or end at...

2019-03-25 20:39:15 125

原创 Tree——No.814 Binary Tree Pruning

No.814 Binary Tree PruningProblem:We are given the head node root of a binary tree, where additionally every node's value is either a 0 or a 1.Return the same tree where every subtree (of the gi...

2019-03-25 20:38:08 119

原创 Tree——No.110 Balanced Binary Tree

No.110 Balanced Binary TreeProblem:Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as:a binary tree in which the depth of the...

2019-03-24 17:41:19 101 1

原创 Tree——No.111 Minimum Depth of Binary Tree

Problem: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.Explanation:计算树的最小深度My T...

2019-03-24 17:39:40 109 1

原创 Tree——No.236 Lowest Common Ancestor of a Binary Tree

No.236 Lowest Common Ancestor of a Binary TreeProblem: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 ...

2019-03-23 19:13:40 94

原创 Tree——No.236 Lowest Common Ancestor of a Binary Tree

No.236 Lowest Common Ancestor of a Binary TreeProblem: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: “...

2019-03-20 20:53:03 101

原创 Tree——No.257 Binary Tree Paths

Problem:Given a binary tree, return all root-to-leaf paths.Explanation:找出一棵树的所有路径。My Thinking:简单递归即可。My Solution:class Solution { public List<String> binaryTreePaths(TreeNode ...

2019-03-20 20:51:16 120

原创 Tree——No.129 Sum Root to Leaf Numbers

Problem: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-&gt;2-&gt;3 which represents the number 123.Fin...

2019-03-17 23:22:15 135

原创 Tree——No.107 Binary Tree Level Order Traversal II

Problem:Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).Explanation:对树从下到上进行层序遍历。My Thinking:...

2019-03-16 21:23:20 110

原创 Tree——No.102 Binary Tree Level Order Traversal

Problem:Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).Explanation:对树进行层序遍历。My Thinking:My Solution:Optimum Thinking:...

2019-03-16 21:22:21 106

原创 Tree——No.113 Path Sum II

Problem:Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.Explanation:给出一棵树和一个数值,找出从根结点到叶子结点的n条路...

2019-03-16 21:20:46 131

原创 Tree——No.112 Path Sum

Problem:Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.Explanation:给出一棵树和一个数值,找出从根结点到叶子结点是否存在...

2019-03-16 21:19:34 115

原创 LinkedList——No.234 Palindrome Linked List

Problem:Given a singly linked list, determine if it is a palindrome.Explanation:判断链表是否回文。My Thinking:使用快慢指针找到链表中点,将慢指针的结点存入栈,注意需要判断奇数还是偶数,随后慢指针继续移动,并与栈中元素判断相等。My Solution:class Solution...

2019-03-11 21:40:47 126

原创 Tree——No.104 Maximum Depth of Binary Tree

Problem: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.Explanation:计算树的最大深度。My ...

2019-03-11 21:29:43 114

原创 Tree——No.589 N-ary Tree Preorder Traversal

Problem:Given an n-ary tree, return the preorder traversal of its nodes' values.Explanation:对n叉树进行前序遍历。My Thinking:使用递归,在二叉树的基础上对每个结点的孩子进行遍历递归。 使用栈进行迭代,My Solution:(1)class Solution {...

2019-03-11 21:28:01 169

原创 Tree——No.590 N-ary Tree Postorder Traversal

Problem:Given an n-ary tree, return the postorder traversal of its nodes' values.Explanation:对n叉树进行后序遍历。My Thinking:使用递归,在二叉树的基础上对每个结点的孩子进行遍历递归。 使用栈进行迭代。My Solution:(1)class Solution ...

2019-03-11 21:26:12 261

原创 Tree——No.101 Symmetric Tree

Problem:Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).Explanation:判断一棵树是否对称。My Thinking:My Solution:Optimum Thinking:使用递归,再复制一棵树,对树1的左结点和树...

2019-03-10 18:43:20 150

原创 Tree——No.100 Same Tree

Problem:Given two binary trees, write a function to check if they are the same or not.Two binary trees are considered the same if they are structurally identical and the nodes have the same value....

2019-03-10 17:20:15 340

原创 Tree——No.617 Merge Two Binary Trees

Problem:Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not.You need to merge them into a new b...

2019-03-10 17:19:01 345

原创 Tree——No.94 Binary Tree Inorder Traversal

Problem:Given a binary tree, return the inorder traversal of its nodes' values.Explanation:中序遍历给定二叉树My Thinking:使用常规递归进行中序遍历,不过这里需要添加一个函数,才能将结果列表作为参数传递。My Solution:class Solution { ...

2019-03-10 17:15:56 330

原创 LinkedList——No.203 Remove Linked List Elements

Problem:Remove all elements from a linked list of integers that have value val.Explanation:删除链表中所有指定值的结点。My Thinking:遍历结点并判断即可。My Solution:class Solution { public ListNode removeEle...

2019-03-10 17:11:25 129

原创 LinkedList——No.142:Linked List Cycle II

Problem:Given a linked list, return the node where the cycle begins. If there is no cycle, return null.To represent a cycle in the given linked list, we use an integer pos which represents the pos...

2019-03-05 20:19:09 225

原创 LinkedList——No.237:Delete node in a linkedlist

Problem:Given a linked list, swap every two adjacent nodes and return its head.You may not modify the values in the list's nodes, only nodes itself may be changed.Explanation:给定一个链表,交换相邻的两个结点,...

2019-03-04 18:54:02 260

原创 LinkedList——No.141:Linked List Cycle

Problem:Given a linked list, determine if it has a cycle in it.To represent a cycle in the given linked list, we use an integer pos which represents the position (0-indexed) in the linked list whe...

2019-03-04 18:51:21 273

原创 LinkedList——No.83 Remove Duplicates from Sorted List

Problem:Given a sorted linked list, delete all duplicates such that each element appear only once.Explanation:给定一个排序后的列表,将其重复元素删除,即每个元素只出现一遍。My Thinking:建立一个布尔型数组用于保存元素出现的情况,如元素2出现过,则a[2]=tr...

2019-03-04 18:49:19 266

空空如也

空空如也

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

TA关注的人

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