原创 LeetCode 1110. Delete Nodes And Return Forest(java)

Given the root of a binary tree, each node in the tree has a distinct value. After deleting all nodes with a value

原创 LeetCode 1111. Maximum Nesting Depth of Two Valid Parentheses Strings(java)

A string is a valid parentheses string (denoted VPS) if and only if it consists of “(” and “)” characters only, and

原创 LeetCode 1040. Moving Stones Until Consecutive II(java)

On an infinite number line, the position of the i-th stone is given by stones[i]. Call a stone an endpoint stone i

原创 LeetCode1033. Moving Stones Until Consecutive(java)

Three stones are on a number line at positions a, b, and c. Each turn, you pick up a stone at an endpoint (ie., eit

原创 KMP算法:兩個字符串的匹配,S1裏匹配S2

通過創建一個部分匹配表來優化指針後移的效率。 http://www.ruanyifeng.com/blog/2013/05/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm.html

原创 432. All O`one Data Structure(java)

Implement a data structure supporting the following operations: Inc(Key) - Inserts a new key with value 1. Or incre

原创 390. Elimination Game(約瑟夫環)

There is a list of sorted integers from 1 to n. Starting from left to right, remove the first number and every othe

原创 685. Redundant Connection II(java)

In this problem, a rooted tree is a directed graph such that, there is exactly one node (the root) for which all ot

原创 684. Redundant Connection(java)

In this problem, a tree is an undirected graph that is connected and has no cycles. The given input is a graph that

原创 647. Palindromic Substrings(java)

Given a string, your task is to count how many palindromic substrings in this string. The substrings with different

原创 二進制作爲hashset存放visited,獲取和設置第n位的值

獲取x第n位的值:(x>>n) & 1 設置x第n位的值爲1:x = x || 1<<n

原创 LeetCode 815. Bus Routes(java)

We have a list of bus routes. Each routes[i] is a bus route that the i-th bus repeats forever. For example if route

原创 53. Maximum Subarray(寫1186順便複習一下這道題的兩種寫法)

Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest su

原创 LeetCode 1186. Maximum Subarray Sum with One Deletion(java)

Given an array of integers, return the maximum sum for a non-empty subarray (contiguous elements) with at most one

原创 LeetCode 743. Network Delay Time(Dijistra算法)

There are N network nodes, labelled 1 to N. Given times, a list of travel times as directed edges times[i] = (u, v,