Description
https://leetcode.com/problems/decode-string/description/
Solution
1 | class Solution(object): |
Why don't you come to your senses?
https://leetcode.com/problems/decode-string/description/
1 | class Solution(object): |
https://leetcode.com/problems/sliding-window-maximum/description/
Quite straightforward, use a heap to maitain the maxium and minium dynamically.
1 | import java.util.*; |
https://leetcode.com/problems/largest-number/description/
Write a comparactor.
1 | class Solution: |
When compare which string is larger, the straight forward way is experiment, this is how things worked in this question. There is no bothering analyse why the left larger than right, but just compare it.
https://leetcode.com/problems/group-anagrams/description/
1 | class Solution: |
But the performance is so pool.
Sort the word by char, then use the sorted string as key in hash table
Given the length of word is n
The time consuming on each item is O(n x logn) on sorting method, the one on the other method is (5*n)
If the length of the word is short, the constant item is quite large compared to the length of the word, which is the case in this question. so the your-own-hash way performance poorly.
https://leetcode.com/problems/combination-sum/description/
The naive implementation of BFS, in this algorithm, we need a lot of space to record the state, and the time spent on copying these states is tremendous.
1 | class Solution(object): |
1 | class Solution(object): |
1 | class Solution(object): |
But the result is upsetting, the recursive method performs better than the non-recursive solution.
https://leetcode.com/problems/merge-intervals/description/
The key point here is to sort all the intervals, then we add each interval by order to merge(insert) into the new intervals.
1 | # Definition for an interval. |
https://leetcode.com/problems/longest-palindromic-subsequence/description/
The code is quite straightforward. The recursive formule is the following:
The string range from i to j can be reduced to the smaller case by two situations:
If the char at i and j is equal, then the largest prlindromic subseq is [i+1, j-1] + 2
Else, the largest prlindromic subseq is the larger value of [i+1, j], [i, j+1]
1 | class Solution { |
https://leetcode.com/problems/palindromic-substrings/description/
1 | class Solution { |
No result yet
https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal/description/
Two things need paying attention:
1 | /** |
This is a cliche problem, all I have learned is don’t forget the corner case of head node in linkedlist problem!!!!!!!!!
https://leetcode.com/problems/remove-nth-node-from-end-of-list/description/
1 | /** |