Golang

LeetCode:811. Subdomain Visit Count

Publish Date : 2020-05-12 10:36 問題: A website domain like “discuss.leetcode.com” consists of various subdomains. At the top level, we have “com”, at the next level, we have “leetcode.com”

LeetCode: 944. Delete Columns to Make Sorted

Publish Date : 2020-05-12 10:32 題目: We are given an array A of N lowercase letter strings, all of the same length. Now, we may choose any set of deletion indices, and for each string, we delete all the characters in those indices. For example, if we have an array A = ["abcdef","uvwxyz"] and deletion indices {0, 2, 3}, then the final array after deletions is ["bef", "vyz"],

LeetCode: 700 Search in a Binary Search Tree

Publish Date : 2020-03-18 15:34 題目: Given the root node of a binary search tree (BST) and a value. You need to find the node in the BST that the node’s value equals the given value. Return the subtree rooted with that node. If such node doesn’t exist, you should return NULL. For example, Given the tree:

LeetCode:933. Number of Recent Calls

Publish Date : 2020-03-17 14:22 題目: Write a class RecentCounter to count recent requests. It has only one method: ping(int t), where t represents some time in milliseconds. Return the number of pings that have been made from 3000 milliseconds ago until now. Any ping with time in [t - 3000, t] will count, including the current ping. It is guaranteed that every call to ping uses a

LeetCode: 852. Peak Index in a Mountain Array

Publish Date : 2020-03-13 09:58 題目: Let’s call an array A a mountain if the following properties hold: A.length >= 3 There exists some 0 < i < A.length - 1 such that A[0] < A[1] < ... A[i-1] < A[i] > A[i+1] > ... > A[A.length - 1] Given an array that is definitely a mountain, return any i such that A[0] <

Leetcode: 942. DI String Match

Publish Date : 2020-03-03 16:54 題目: Given a string S that only contains “I” (increase) or “D” (decrease), let N = S.length. Return any permutation A of [0, 1, ..., N] such that for all i = 0, ..., N-1: * If S[i] == "I", then A[i] < A[i+1] * If S[i] == "D", then A[i] > A[i+1] 範例: Input: "IDID" Output:

Leetcode:461. Hamming Distance

Publish Date : 2020-03-02 13:28 題目: The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Given two integers x and y, calculate the Hamming distance. 範例: Input: x = 1, y = 4Output: 2Explanation:1 (0 0 0 1)4 (0 1 0 0) ↑ ↑The above arrows point to positions where the corresponding bits are

Leetcode:977. Squares of a Sorted Array

Publish Date : 2020-02-24 14:10 題目: Given an array of integers A sorted in non-decreasing order, return an array of the squares of each number, also in sorted non-decreasing order. 範例: Input: [-4,-1,0,3,10]Output: [0,1,9,16,100] Input: [-7,-3,2,3,11]Output: [4,9,9,49,121] 在LeetCode中使用Golang的庫很方便 不用impo

LeetCode:617 Merge Two Binary Trees

Publish Date : 2020-02-21 14:00 題目: 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.

LeetCode:938. Range Sum of BST

Publish Date : 2020-02-19 15:48 Given the root node of a binary search tree, return the sum of values of all nodes with value between L and R (inclusive). The binary search tree is guaranteed to have unique values. Input: root = [10,5,15,3,7,null,18], L = 7, R = 15Output: 32 目前遇到BST類型的題目都是有關遞迴的 /**