摘要:
Given a string, your task is to count how many palindromic substrings in this string. The substrings with different start indexes or end indexes are c 阅读全文
摘要:
Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring. For "(()", the lo 阅读全文
摘要:
Better Solution: DFS, but only scan all the matches once! If a match can not make the 1st edge, then we do not discard it, we try 2nd, 3rd, 4th edge 阅读全文
摘要:
DFS, my solution is to fill each edge of the square one by one. DFS to construct the 1st, then 2nd, then 3rd, then 4th. For each edge I scan all the m 阅读全文
摘要:
Backtracking: time complexity O(N!) Use HashMap to store the initial debts of each person, negative means the person sends money to others, positive m 阅读全文
摘要:
Taken from GeeksforGeeks Following is a simple algorithm to find out whether a given graph is Birpartite or not using Breadth First Search (BFS) :- Al 阅读全文
摘要:
Heap的介绍1,介绍2,要注意complete tree和full tree的区别, Heap是complete tree;Heap里面 i 的 children分别是 i*2+1 和 i*2+2,i 的 parent是 (i-1)/2 Heapify的基本思路就是:Given an array 阅读全文
摘要:
类似于find kth small element in sorted matrix, 另外数组是个好东西,在构造heap 的元素的时候 Some observations: For every numbers in nums1, its best partner(yields min sum) a 阅读全文
摘要:
Analysis: Solution 1: The greedy algorithm is that in each step, select the char with highest remaining count if possible (if it is not in the waiting 阅读全文
摘要:
方法1:Time Complexity O(NK) 暂时只有两个Heap的做法,缺点:In this problem, it is necessary to be able remove elements that are not necessarily at the top of the heap 阅读全文