Liam's Blog


  • Home

  • Archives

  • Tags

  • Categories

  • Photos

  • About

LeetCode #222 Count Complete Tree Nodes

Posted on 2018-10-08 | Post modified 2018-10-10 | In Languages , LeetCode , Python , Difficulties , Algorithms , Data Structures , Medium , Binary Tree , Binary Search

Problem

Given a complete binary tree, count the number of nodes.

Example

1
2
3
4
5
6
7
8
Input: 
1
/ \
2 3
/ \ /
4 5 6

Output: 6

Note

Definition of a complete binary tree from Wikipedia:
In a complete binary tree every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible. It can have between 1 and 2h nodes inclusive at the last level h.

Read more »

LeetCode #856 Score of Parentheses

Posted on 2018-10-08 | Post modified 2018-10-08 | In Languages , LeetCode , Python , Difficulties , Algorithms , Medium , Stack

Problem

Given a balanced parentheses string S, compute the score of the string based on the following rule:

  • () has score 1
  • AB has score A + B, where A and B are balanced parentheses strings.
  • (A) has score 2 * A, where A is a balanced parentheses string.

Examples

1
2
Input: "()"
Output: 1
1
2
Input: "(())"
Output: 2
1
2
Input: "()()"
Output: 2
1
2
Input: "(()(()))"
Output: 6
Read more »

Advanced Project References

Posted on 2018-10-08 | Post modified 2018-10-10 | In Advanced Project

Evolutionary Visual Analysis of Deep Neural Networks

Key Points in Each Section

1. Introduction

A visual analytics framework for network evolution monitoring needs to possess the following three important capabilities:

  • Monitor neural network evolution
  • Rigorous quantitative evaluation
  • Expand theoretical insights

2. Methodology

2.1 Discriminability Metric

In deep learning, the loss function is a metric for the class-wise discriminability evaluation of the neurons.

How to evaluate those neurons in the inner layers? Due to the lack of ground truth for specific classes or visual concepts, it is challenging to quantitvatively evaluate them.

*** HOW TO COMPUTE THE DISCRIMINABILITY

References

What is a Loss Function?

Deep Learning: Overview of Neurons and Activation Functions

LeetCode #442 Find All Duplicates in an Array

Posted on 2018-10-08 | Post modified 2018-10-08 | In Languages , LeetCode , Python , Difficulties , Data Structures , Medium , Array

Problem

Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.

Find all the elements that appear twice in this array.

Could you do it without extra space and in O(n) runtime?

Example

1
2
3
4
5
Input:
[4,3,2,7,8,2,3,1]

Output:
[2,3]
Read more »

LeetCode #515 Find Largest Value in Each Tree Row

Posted on 2018-10-08 | Post modified 2018-10-08 | In Languages , LeetCode , Python , Difficulties , Algorithms , Data Structures , Medium , Binary Tree , Breadth-first Search , Depth-first Search , Deque

Problem

You need to find the largest value in each row of a binary tree.

Example

1
2
3
4
5
6
7
8
9
Input: 

1
/ \
3 2
/ \ \
5 3 9

Output: [1, 3, 9]
Read more »

LeetCode #540 Single Element in a Sorted Array

Posted on 2018-10-08 | Post modified 2018-10-08 | In Languages , LeetCode , Python , Difficulties , Algorithms , Data Structures , Medium , Array , Divide and Conquer , Binary Search

Problem

Given a sorted array consisting of only integers where every element appears twice except for one element which appears once. Find this single element that appears only once.

Examples

1
2
Input: [1,1,2,3,3,4,4,8,8]
Output: 2
1
2
Input: [3,3,7,7,10,11,11]
Output: 10
Read more »

LeetCode #654 Maximum Binary Tree

Posted on 2018-10-08 | Post modified 2018-10-08 | In Languages , LeetCode , Python , Difficulties , Algorithms , Data Structures , Medium , Array , Divide and Conquer

Problem

Given an integer array with no duplicates. A maximum tree building on this array is defined as follow:

  1. The root is the maximum number in the array.
  2. The left subtree is the maximum tree constructed from left part subarray divided by the maximum number.
  3. The right subtree is the maximum tree constructed from right part subarray divided by the maximum number.

Construct the maximum tree by the given array and output the root node of this tree.

Example

1
2
3
4
5
6
7
8
9
10
Input: [3,2,1,6,0,5]
Output: return the tree root node representing the following tree:

6
/ \
3 5
\ /
2 0
\
1
Read more »

LeetCode #814 Binary Tree Pruning

Posted on 2018-10-08 | Post modified 2018-10-08 | In Languages , LeetCode , Python , Difficulties , Algorithms , Data Structures , Medium , Binary Tree , Depth-first Search

Problem

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 given tree) not containing a 1 has been removed.

(Recall that the subtree of a node X is X, plus every node that is a descendant of X.)

Examples

1
2
3
4
5
6
Input: [1,null,0,0,1]
Output: [1,null,0,null,1]

Explanation:
Only the red nodes satisfy the property "every subtree not containing a 1".
The diagram on the right represents the answer.

img

1
2
Input: [1,0,1,0,0,0,1]
Output: [1,null,1,null,1]

img

1
2
Input: [1,1,0,1,1,0,1,0]
Output: [1,1,0,1,1,null,1]

img

Read more »

LeetCode #513 Find Bottom Left Tree Value

Posted on 2018-10-07 | Post modified 2018-10-07 | In Languages , LeetCode , Python , Difficulties , Algorithms , Data Structures , Medium , Binary Tree , Breadth-first Search , Depth-first Search

Problem

Given a binary tree, find the leftmost value in the last row of the tree.

Examples

1
2
3
4
5
6
7
8
Input:

2
/ \
1 3

Output:
1
1
2
3
4
5
6
7
8
9
10
11
12
Input:

1
/ \
2 3
/ / \
4 5 6
/
7

Output:
7

What If?

  • Input is an empty tree?
Read more »

LeetCode #739 Daily Temperatures

Posted on 2018-10-07 | Post modified 2018-10-07 | In Languages , LeetCode , Python , Difficulties , Algorithms , Medium , Stack

Problem

Given a list of daily temperatures, produce a list that, for each day in the input, tells you how many days you would have to wait until a warmer temperature. If there is no future day for which this is possible, put 0 instead.

For example, given the list temperatures = [73, 74, 75, 71, 69, 72, 76, 73], your output should be [1, 1, 4, 2, 1, 1, 0, 0].

Read more »
1…567…18
Liam Wang

Liam Wang

Liam's Personal Blog

174 posts
133 categories
64 tags
© 2019 Liam Wang
Powered by Hexo
Theme - NexT.Muse