p*****2 发帖数: 21240 | 1 写了一个练练手。
import java.util.*;
class Node
{
Node[] children=new Node[26];
public Node Set(char c)
{
Node node=new Node();
children[c-'a']=node;
return node;
}
public Node Get(char c)
{
return children[c-'a'];
}
}
class Trie
{
Node root=new Node();
public void Add(String word)
{
int i=0;
Node node=root;
while(i
{
char c=word.charAt(i);
if(node.Ge... 阅读全帖 |
|
p*****2 发帖数: 21240 | 2 写了一个练练手。
import java.util.*;
class Node
{
Node[] children=new Node[26];
public Node Set(char c)
{
Node node=new Node();
children[c-'a']=node;
return node;
}
public Node Get(char c)
{
return children[c-'a'];
}
}
class Trie
{
Node root=new Node();
public void Add(String word)
{
int i=0;
Node node=root;
while(i
{
char c=word.charAt(i);
if(node.Ge... 阅读全帖 |
|
n*******n 发帖数: 45 | 3 木有用DP....
public int lengthOfLongestSubstring(String s) {
if (s == null) {
return 0;
}
if (s.length() < 2) {
return s.length();
}
int maxLength = 0;
int totalLen = s.length();
int currentLen = 0;
int cStart = 0;
Map indexMap = new HashMap<>();
while((totalLen - cStart) > maxLength) {
for(int i = cStart; i < totalLen; i++) {
Character cur = s.char... 阅读全帖 |
|
f********a 发帖数: 367 | 4 电面2:
还是一个国人大哥,LeetCode上的Insert Interval,API稍微有点变化,给的是一个链
表节点。
由于还有时间,还考了一个count tweets的设计题。需要实现如下API:
class CountingSvc {
void tweet(long timestamp, int tweetLength);
double avgLength(long begin, long end, long threshold);
};
另外给了一个hint,TreeMap,让自己customize一下object。
可惜我一看是range query就往线段树上想了,于是给出了如下结构,并解释了原理。
class Node {
long totalLen;
long count;
long begin;
long end;
Node left;
Node right;
}
最后追问了下如何去做模糊处理。我还是在线段树上想,就加了一个threshold。
double avgL... 阅读全帖 |
|
f********a 发帖数: 367 | 5 这个TreeMap怎么弄啊? key是timestamp? Object就是{totalLen, count}? |
|