Publish Date : 2020-09-16 14:43 題目: Given a binary tree, each node has value 0 or 1. Each root-to-leaf path represents a binary number starting with the most significant bit. For example, if the path is 0 -> 1 -> 1 -> 0 -> 1, then this could represent 01101 in binary, which is 13. For all leaves in the tree, consider the numbers represented by the path
Publish Date : 2020-09-11 10:14 題目: The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1. That is, F(0) = 0, F(1) = 1F(N) = F(N - 1) + F(N - 2), for N > 1. Given N, calculate F(N). Example:
Publish Date : 2020-09-11 10:11 題目: Given two integer arrays arr1 and arr2, and the integer d, return the distance value between the two arrays. The distance value is defined as the number of elements arr1[i] such that there is not any element arr2[j] where |arr1[i]-arr2[j]| <= d. 範例: Input: arr1 = [4,5,8], arr2 = [10,9,1,8], d = 2Output: 2 Explanation: For arr1[0]=4 we have: |4-10|=6
Publish Date : 2020-09-11 10:10 題目: A binary tree is univalued if every node in the tree has the same value. Return true if and only if the given tree is univalued. Example: Input: [1,1,1,1,1,null,1] Output: true 解法: 這題只是要判斷二元樹中所有val是否相同 一
Publish Date : 2020-08-03 09:27 問題: Every email consists of a local name and a domain name, separated by the @ sign. For example, in alice@leetcode.com, alice is the local name, and leetcode.com is the domain name. Besides lowercase letters, these emails may contain '.'s or '+'s. If you add periods ('.') between some characters in the local name part of an email address, mail sent there will
Publish Date : 2020-07-30 14:56 題目: Given a n-ary 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. Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value (See examples). 範例: Input: root = [1,null,3,2,4,null,5,6] Output: 3 解
Publish Date : 2020-07-08 23:19 題目: Given a non-empty, singly linked list with head node head, return a middle node of linked list. If there are two middle nodes, return the second middle node. 範例: Input: [1,2,3,4,5] Output: Node 3 from this list (Serialization: [3,4,5]) The returned node has value 3. (The judge's serialization of this node is [3,4,5]). Note that we returned a ListNode object
Publish Date : 2020-05-20 17:19 題目: Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order. 範例: Input: "Let's take LeetCode contest" Output: "s'teL ekat edoCteeL tsetnoc" 解法: 這題就是把句子的單字反過來 在這裡做stri
Publish Date : 2020-05-19 15:18 題目: Given a m * n matrix mat of ones (representing soldiers) and zeros (representing civilians), return the indexes of the k weakest rows in the matrix ordered from the weakest to the strongest.A row i is weaker than row j, if the number of soldiers in row i is less than the number of soldiers in row j, or they have the
Publish Date : 2020-05-18 15:30 題目: Given an array A of non-negative integers, half of the integers in A are odd, and half of the integers are even. Sort the array so that whenever A[i] is odd, i is odd; and whenever A[i] is even, i is even. You may return any answer array that satisfies this condition. 範例: Input: [4,2,5,7] Output: [4,5,2,7] Explanation: [4,7,2,5], [2,5,4,7],