OneCoder


  • 首页

  • 归档

  • 标签

  • 关于

  • 搜索

LeetCode Pascal's Triangle II

发表于 2017-12-05 | 阅读次数

Problem

Given an index k, return the kth row of the Pascal’s triangle.

For example, given k = 3, Return [1,3,3,1].

Note: Could you optimize your algorithm to use only O(k) extra space?

即直接返回杨辉三角形的某一行元素,额外要求是只让使用O(k)的空间

阅读全文 »

【翻译】 TensorFlow如何工作

发表于 2017-12-01 | 阅读次数

学习TensorFlow过程中读的一篇文章,索性就翻译出来,虽然收获感觉不是很大。

原文地址:How TensorFlow Works

https://github.com/nfmcclure/tensorflow_cookbook/blob/master/01_Introduction/01_How_TensorFlow_Works/01_How_TensorFlow_Works.ipynb

阅读全文 »

LeetCode Pascal's Triangle

发表于 2017-12-01 | 阅读次数

Problem

Given numRows, generate the first numRows of Pascal’s triangle.

For example, given numRows = 5, Return

[
     [1],
    [1,1],
   [1,2,1],
  [1,3,3,1],
 [1,4,6,4,1]
]

没记错的话,这个应该叫杨辉三角型。很简单的题

阅读全文 »

LeetCode Path Sum II

发表于 2017-11-30 | 阅读次数

Problem

Given a binary tree and a sum, find all root-to-leaf paths where each path’s sum equals the given sum.

For example: Given the below binary tree and sum = 22,

              5
             / \
            4   8
           /   / \
          11  13  4
         /  \    / \
        7    2  5   1

return

[
   [5,4,11,2],
   [5,8,4,5]
]

即Path Sum问题的进一步,不仅仅是判断是否存在路径,而是找出所有的路径。

阅读全文 »

LeetCode Path Sum

发表于 2017-11-27 | 阅读次数

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.

For example: Given the below binary tree and sum = 22,

              5
             / \
            4   8
           /   / \
          11  13  4
         /  \      \
        7    2      1

return true, as there exist a root-to-leaf path 5->4->11->2 which sum is 22.

class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None
阅读全文 »

LeetCode Minimum Depth of Binary Tree

发表于 2017-11-27 | 阅读次数

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.

class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None
阅读全文 »

LeetCode Balanced Binary Tree

发表于 2017-11-23 | 阅读次数

Problem

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 two subtrees of every node never differ by more than 1.

即判断一个二叉树是不是平衡树。平衡的标准就是任何节点的左右子树的高度差不大于1。

阅读全文 »

LeetCode Convert Sorted Array to Binary Search Tree

发表于 2017-11-23 | 阅读次数

Problem

Given an array where elements are sorted in ascending order, convert it to a height balanced BST.

public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }
阅读全文 »

LeetCode Binary Tree Level Order Traversal II

发表于 2017-11-16 | 阅读次数

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).

For example: Given binary tree [3,9,20,null,null,15,7],

    3
   / \
  9  20
    /  \
   15   7

return its bottom-up level order traversal as:

[
  [15,7],
  [9,20],
  [3]
]

按层,从叶子到根输出树种每层的元素。树的定义如下:

public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }
阅读全文 »

LeetCode Maximum Depth of Binary Tree

发表于 2017-11-14 | 阅读次数

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.

求二叉树的最大深度

阅读全文 »
1 … 7 8 9 … 33
LiHongZhe

LiHongZhe

onecoder's blog.

326 日志
8 分类
RSS
Creative Commons
Links
  • 酷壳
  • 酸菜鱼
  • 私塾在线学习网
  • 煮酒品茶
  • 点滴技术博客
  • 思考者日记网·束洋洋
  • 开源视窗
  • 小弟子的网络之路
  • 寄存心–移动开发
  • TicmyBlog
  • 中国程序员人才网
  • 图表秀-在线图表制作
  • IT热血青年
© 2012 - 2022 LiHongZhe
由 Jekyll 强力驱动
主题 - NexT.Muse