YaoyuanHsu

@yuanster

Joined on Feb 11, 2020

  • Description Given an integer n, return the least number of perfect square numbers that sum to n. A perfect square is an integer that is the square of an integer; in other words, it is the product of some integer with itself. For example, 1, 4, 9, and 16 are perfect squares while 3 and 11 are not. Examples Example 1: Input: n = 12 Output: 3 Explanation: 12 = 4 + 4 + 4.
     Like  Bookmark
  • Daily 232. Implement Queue using Stacks(2022.12.16) Sheep: https://hackmd.io/@sheep1221/BJBH-z5do Yuan: https://hackmd.io/H4JXMj8YS4q6rt4hE-YBBQ?view 1143. Longest Common Subsequence(2022.12.15) Yuan: https://hackmd.io/@yuanster/S1N2G2ddj
     Like  Bookmark
  • 232. Implement Queue using Stacks(2022.12.17) 1143. Longest Common Subsequence(2022.12.15) 931. Minimum Falling Path Sum(2022.12.13) 70. Climbing Stairs(2022.12.12) 124. Binary Tree Maximum Path Sum(2022.12.11) 1026. Maximum Difference Between Node and Ancestor(2022.12.10) 872. Leaf-Similar Trees(2022.12.08) 938. Range Sum of BST(2022.12.07) 328. Odd Even Linked List(2022.12.06) 2256. Minimum Average Difference(2022.12.05)
     Like  Bookmark
  • Description Implement a first in first out (FIFO) queue using only two stacks. The implemented queue should support all the functions of a normal queue (push, peek, pop, and empty). Implement the MyQueue class: void push(int x) Pushes element x to the back of the queue. int pop() Removes the element from the front of the queue and returns it. int peek() Returns the element at the front of the queue. boolean empty() Returns true if the queue is empty, false otherwise.
     Like  Bookmark
  • Description Given two strings text1 and text2, return the length of their longest common subsequence. If there is no common subsequence, return 0. A subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters. For example, "ace" is a subsequence of "abcde". A common subsequence of two strings is a subsequence that is common to both strings. Examples
     Like  Bookmark
  • Description Given an n x n array of integers matrix, return the minimum sum of any falling path through matrix. A falling path starts at any element in the first row and chooses the element in the next row that is either directly below or diagonally left/right. Specifically, the next element from position (row, col) will be (row + 1, col - 1), (row + 1, col), or (row + 1, col + 1). Examples Example 1: Input: matrix = [[2,1,3],[6,5,4],[7,8,9]] Output: 13
     Like  Bookmark
  • Description You are climbing a staircase. It takes n steps to reach the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? Examples Example 1: Input: n = 2 Output: 2 Explanation: There are two ways to climb to the top.
     Like  Bookmark
  • Description A path in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence at most once. Note that the path does not need to pass through the root. The path sum of a path is the sum of the node's values in the path. Given the root of a binary tree, return the maximum path sum of any non-empty path. Examples Example 1:
     Like  Bookmark
  • Description Given the root of a binary tree, find the maximum value v for which there exist different nodes a and b where v = |a.val - b.val| and a is an ancestor of b. A node a is an ancestor of b if either: any child of a is equal to b or any child of a is an ancestor of b. Examples Example1 Input: root = [8,3,10,1,6,null,14,null,null,4,7,13] Output: 7
     Like  Bookmark
  • Description Consider all the leaves of a binary tree, from left to right order, the values of those leaves form a leaf value sequence. For example, in the given tree above, the leaf value sequence is (6, 7, 4, 9, 8). Two binary trees are considered leaf-similar if their leaf value sequence is the same. Return true if and only if the two given trees with head nodes root1 and root2 are leaf-similar. Examples
     Like  Bookmark
  • Description Given the root node of a binary search tree and two integers low and high, return the sum of values of all nodes with a value in the inclusive range [low, high]. Examples Example 1: Input: root = [10,5,15,3,7,null,18], low = 7, high = 15 Output: 32 Explanation: Nodes 7, 10, and 15 are in the range [7, 15]. 7 + 10 + 15 = 32.
     Like  Bookmark
  • Description Given the array nums, for each nums[i] find out how many numbers in the array are smaller than it. That is, for each nums[i] you have to count the number of valid j's such that j != i and nums[j] < nums[i]. Return the answer in an array. Examples Example 1: Input: nums = [8,1,2,2,3] Output: [4,0,1,1,3] Explanation:
     Like  Bookmark
  • Description We are given a list nums of integers representing a list compressed with run-length encoding. Consider each adjacent pair of elements [freq, val] = [nums[2*i], nums[2*i+1]] (with i >= 0). For each such pair, there are freq elements with value val concatenated in a sublist. Concatenate all the sublists from left to right to generate the decompressed list. Return the decompressed list. Examples Example 1: Input: nums = [1,2,3,4]
     Like  Bookmark
  • Description Given a string s, reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order. Examples Example 1: Input: s = "Let's take LeetCode contest" Output: "s'teL ekat edoCteeL tsetnoc" Example 2: Input: s = "God Ding"
     Like  Bookmark
  • Description Given the root of a binary tree, return the inorder traversal of its nodes' values. Examples Example1 Input: root = [1,null,2,3] Output: [1,3,2] Example 2: Input: root = []
     Like  Bookmark
  • Description Given a non-negative integer x, return the square root of x rounded down to the nearest integer. The returned integer should be non-negative as well. You must not use any built-in exponent function or operator. For example, do not use pow(x, 0.5) in c++ or x ** 0.5 in python. Examples Example 1: Input: x = 4
     Like  Bookmark
  • Description Implement pow(x, n), which calculates x raised to the power n (i.e., $x^n$). Examples Example 1: Input: x = 2.00000, n = 10 Output: 1024.00000 Example 2: Input: x = 2.10000, n = 3
     Like  Bookmark
  • Description You are given the heads of two sorted linked lists list1 and list2. Merge the two lists in a one sorted list. The list should be made by splicing together the nodes of the first two lists. Return the head of the merged linked list. Examples Example1 Input: list1 = [1,2,4], list2 = [1,3,4]
     Like  Bookmark
  • Description Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An input string is valid if: Open brackets must be closed by the same type of brackets. Open brackets must be closed in the correct order. Every close bracket has a corresponding open bracket of the same type. Examples
     Like  Bookmark
  • Description Given the head of a singly linked list, group all the nodes with odd indices together followed by the nodes with even indices, and return the reordered list. The first node is considered odd, and the second node is even, and so on. Note that the relative order inside both the even and odd groups should remain as it was in the input. You must solve the problem in O(1) extra space complexity and O(n) time complexity. Examples
     Like  Bookmark