上一页 1 ··· 52 53 54 55 56 57 58 59 60 ··· 72 下一页
摘要: 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 阅读全文
posted @ 2017-10-30 09:41 乐乐章 阅读(195) 评论(0) 推荐(0) 编辑
摘要: 题目描述 输入一个链表,从尾到头打印链表每个节点的值。 思路1:stack 1 import java.util.ArrayList; 2 import java.util.Stack; 3 public class Solution { 4 public ArrayList<Integer> pr 阅读全文
posted @ 2017-10-29 22:11 乐乐章 阅读(117) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, return the tilt of the whole tree. The tilt of a tree node is defined as the absolute difference between the sum of all left subt 阅读全文
posted @ 2017-10-29 10:17 乐乐章 阅读(98) 评论(0) 推荐(0) 编辑
摘要: You need to construct a string consists of parenthesis and integers from a binary tree with the preorder traversing way. The null node needs to be rep 阅读全文
posted @ 2017-10-29 09:45 乐乐章 阅读(124) 评论(0) 推荐(0) 编辑
摘要: 题目描述 请实现一个函数,将一个字符串中的空格替换成“%20”。例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy。 思路: 从前往后替换,后面的字符要不断往后移动,要多次移动,所以效率低下,时间复杂度 O(N2)。 从后往前,先计算需要多少空间,然后 阅读全文
posted @ 2017-10-29 08:57 乐乐章 阅读(169) 评论(0) 推荐(0) 编辑
摘要: 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 l 阅读全文
posted @ 2017-10-28 09:48 乐乐章 阅读(121) 评论(0) 推荐(0) 编辑
摘要: 思路 难度简单 1239 给你两棵二叉树: root1 和 root2 。 想象一下,当你将其中一棵覆盖到另一棵之上时,两棵树上的一些节点将会重叠(而另一些不会)。你需要将这两棵树合并成一棵新二叉树。合并的规则是:如果两个节点重叠,那么将这两个节点的值相加作为合并后节点的新值;否则,不为 null 阅读全文
posted @ 2017-10-28 09:42 乐乐章 阅读(106) 评论(0) 推荐(0) 编辑
摘要: 题目描述 在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。 思路: 利用二维数组由上到下,由左到右递增的规律, 那么选取右上角或者左下角的元素a[row][col]与target进行 阅读全文
posted @ 2017-10-27 22:24 乐乐章 阅读(148) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree [1,2,2,3,4,4,3] is symmet 阅读全文
posted @ 2017-10-27 10:10 乐乐章 阅读(139) 评论(0) 推荐(0) 编辑
摘要: 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 阅读全文
posted @ 2017-10-27 09:07 乐乐章 阅读(133) 评论(0) 推荐(0) 编辑
上一页 1 ··· 52 53 54 55 56 57 58 59 60 ··· 72 下一页