朝花夕拾

Clicks&Changes

导航

随笔分类 -  Java

Invert Binary Tree
摘要:Invert a binary tree: 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1简单递归实现,调换左右子树,子树的所有子树结构一并调换了顺序。/** * De... 阅读全文

posted @ 2015-12-07 15:30 Draug 阅读(144) 评论(0) 推荐(0)

二叉树的遍历
摘要:二叉树结点的定义与先序(中左右)、中序(左中右)、后序(左右中)遍历,顺便写个最大深度,都是递归实现,之后再学习非递归的方法。先序遍历的结果为:5,2,4,1,3,8,4,2,9,中序遍历的结果:4,2,1,5,4,8,2,3,9,后序遍历结果:4,1,2,4,2,8,9,3,5。package l... 阅读全文

posted @ 2015-10-07 17:04 Draug 阅读(135) 评论(0) 推荐(0)

Maximum Depth of Binary Tree
摘要:二叉树最大深度的递归实现。/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNo... 阅读全文

posted @ 2015-10-07 15:58 Draug 阅读(116) 评论(0) 推荐(0)

Majority Element II
摘要:Given an integer array of sizen, find all elements that appear more than⌊ n/3 ⌋times. The algorithm should run in linear time and in O(1) space.方法很笨,其... 阅读全文

posted @ 2015-10-02 22:06 Draug 阅读(174) 评论(0) 推荐(0)

LeetCode-Pascal's Triangle
摘要:菜鸟刷的第一题LeetCode,毫无任何优化,虽然是一道easy的题目,看到Accepted心里还是甚是欣慰的。 1 import java.util.ArrayList; 2 import java.util.List; 3 import java.util.Scanner; 4 public c... 阅读全文

posted @ 2015-10-02 21:27 Draug 阅读(156) 评论(0) 推荐(0)