This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| def dfs(root_path): | |
| for ele in os.listdir(root_path): | |
| path = os.path.join(root_path, ele) | |
| if os.path.isfile(path): | |
| # do something... | |
| else: | |
| dfs(path) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * INPUT: graph G(V, E) with n vertix and m edges, starting vertex s | |
| * OUTPUT: shortest distance from s to each node, stored in array d[MAX] | |
| * TIME COMPLEXITY: O((m + n) * lg(n)) | |
| * SPACE COMPLEXITY: O(n^2) | |
| */ | |
| const int MAX = 205; | |
| const int INF = 0x7fffffff; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * TIME COMPLEXITY: O(n * lgn) | |
| * SPACE COMPLEXITY: O(n) | |
| */ | |
| const int maxn = 2e4 + 10; | |
| // all indexes start from 0 | |
| struct SuffixArray { | |
| int len, str[maxn], sa[maxn], rank[maxn], height[maxn], bucket[maxn]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * INPUT: two strings: W and T | |
| * OUTPUT: a integer vector, containing subscripts of T that W appears as sub-string | |
| * TIME COMPLEXITY: O(|W| + |T|) | |
| * SPACE COMPLEXITY: O(|W| + |T|) | |
| */ | |
| class Kmp { | |
| std::string word, text; | |
| int w_len, t_len; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * INPUT: a string and its length; | |
| * OUTPUT: an integer n, after n-bit cyclic shift left, the new string is minimum in dictionary order | |
| * TIME COMPLEXITY: O(n) | |
| * SPACE COMPLEXITY: O(n) | |
| */ | |
| int MinRepresentation(char *s) { | |
| int len = strlen(s); | |
| memcpy(s + len, s, len); |
NewerOlder