0%

Maximum Product of Three Numbers – LeetCode 628

Problem

Description

Given an integer array, find three numbers whose product is maximum and output the maximum product.

Read more »

Merge Two Binary Trees – LeetCode 617

Problem

Description

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 binary tree. The merge rule is that if two nodes overlap, then sum node values up as the new value of the merged node. Otherwise, the NOT null node will be used as the node of new tree.

Read more »

Construct String from Binary Tree – LeetCode 606

Problem

Description

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 represented by empty parenthesis pair “()”. And you need to omit all the empty parenthesis pairs that don’t affect the one-to-one mapping relationship between the string and the original binary tree.

Read more »

Add Binary – LeetCode 67

Problem

Description

Suppose you have a long flowerbed in which some of the plots are planted and some are not. However, flowers cannot be planted in adjacent plots - they would compete for water and both would die.

Given a flowerbed (represented as an array containing 0 and 1, where 0 means empty and 1 means not empty), and a number n, return if n new flowers can be planted in it without violating the no-adjacent-flowers rule.

Read more »

Minimum Index Sum of Two Lists – LeetCode 599

Problem

Description

Suppose Andy and Doris want to choose a restaurant for dinner, and they both have a list of favorite restaurants represented by strings.

You need to help them find out their common interest with the least list index sum. If there is a choice tie between answers, output all of them with no order requirement. You could assume there always exists an answer.

Read more »

Range Addition II – LeetCode 598

Problem

Description

Given an m * n matrix M initialized with all 0’s and several update operations.

Operations are represented by a 2D array, and each operation is represented by an array with two positive integers a and b, which means M[i][j] should be added by one for all 0 <= i < a and 0 <= j < b.

You need to count and return the number of maximum integers in the matrix after performing all the operations.

Read more »

Longest Harmonious Subsequence – LeetCode 594

Problem

Description

We define a harmonious array is an array where the difference between its maximum value and its minimum value is exactly 1.

Now, given an integer array, you need to find the length of its longest harmonious subsequence among all its possible subsequences.

Read more »

N-ary Tree Postorder Traversal – LeetCode 590

Problem

Description

Given an n-ary tree, return the postorder traversal of its nodes’ values.

Read more »

N-ary Tree Preorder Traversal – LeetCode 589

Problem

Description

Given an n-ary tree, return the preorder traversal of its nodes’ values.

Read more »

Shortest Unsorted Continuous Subarray – LeetCode 581

Problem

Description

Given an integer array, you need to find one continuous subarray that if you only sort this subarray in ascending order, then the whole array will be sorted in ascending order, too.

You need to find the shortest such subarray and output its length.

Read more »