package com.xiaomi.mahout_test;

public class Trie {
private Node root;

public Trie() {
root = new Node();
}

public static void addWord(Node root, String sentence) {
Node cur = root;
for (char tmp : sentence.toCharArray()) {
int index = tmp - 'a';
if (cur.chlidrens[index] == null) {
cur.chlidrens[index] = new Node();
}
cur = cur.chlidrens[index];
cur.ch = tmp;
}
}
public static boolean findWord(Node root, String sentence) {
Node cur = root;
for (char tmp : sentence.toCharArray()) {
int index = tmp - 'a';
if (cur.chlidrens[index] == null) {
return false;
}
cur = cur.chlidrens[index];
}
return true;
}
public static void main(String[] args) {
String[] str = {"asdf", "asji", "bjkl", "cdsdf", "jdsfk"};
Trie trie = new Trie();
for (String s : str) {
addWord(trie.root, s);
}
if (findWord(trie.root, "jdsfk")) {
System.out.println("string is found~");
} else {
System.out.println("not found~");
}
}
static class Node {
Node[] chlidrens = new Node[26];
char ch;
}
}

posted @ 2015-08-11 15:29 glose 阅读(254) 评论(1) 推荐(0) 编辑
摘要: 记录一下~jQuery Ajax 实例演示输入姓名:输入密码:ajax提交post提交get提交login.php复制代码代码如下:$_REQUEST['username'],'password'=>$_REQUEST['password']));?> 阅读全文
posted @ 2014-04-15 15:17 glose 阅读(171) 评论(0) 推荐(0) 编辑
摘要: awk '{a[$1]+=1;if(a[$1]==1){print $0}}'awk -F ',' '{print $1, $6}' IS.csv | sort -k1n -k2n | awk '!a[$1]++'> min 阅读全文
posted @ 2013-11-06 13:49 glose 阅读(228) 评论(0) 推荐(0) 编辑
摘要: c++ primer effective c++inside the c++ object modelC++.Templates_TheCompleteGuide 阅读全文
posted @ 2013-10-31 08:34 glose 阅读(195) 评论(0) 推荐(0) 编辑
摘要: http://developer.51cto.com/art/201203/321041.htm 阅读全文
posted @ 2013-10-11 19:54 glose 阅读(194) 评论(0) 推荐(0) 编辑
摘要: for a in {0..98};do echo $a; done | awk '{printf("%02d",$0);}' > machine.list 阅读全文
posted @ 2013-09-06 15:04 glose 阅读(165) 评论(0) 推荐(0) 编辑
摘要: IntelliJ IDEAsublime 阅读全文
posted @ 2013-08-23 19:32 glose 阅读(183) 评论(0) 推荐(0) 编辑
摘要: 1、源码安装mysql 以root用户首先安装libaio-0.3.104.tar.gz tar zxvflibaio-0.3.104.tar.gz cdlibaio-0.3.104make prefix=/lib64 installexport LD_LIBRARY_PATH=/lib64/lib 解压mysql tar zxvfmysql-5.5.29-linux2.6-x86_64.tar.gz ln -smysql-5.5.29-linux2.6-x86_64 mysql cd mysql 执行./scripts/mysql_install_db --datadir=/home/hiv 阅读全文
posted @ 2013-08-08 17:22 glose 阅读(492) 评论(0) 推荐(0) 编辑
摘要: 执行shell脚本 错误提示如下: bash: ./back : bad interpreter:No such file or directory因为操作系统是windows,在windows下编辑的脚本,所以有可能有不可见字符。从你的脚本及报告的错误看来, 很有可能是你的脚本文件是DOS格式的, 即每一行的行尾以\r\n来标识, 其ASCII码分别是0x0D, 0x0A.可以有很多种办法看这个文件是DOS格式的还是UNIX格式的, 还是MAC格式的vi filename然后用命令:set ff?可以看到dos或unix的字样. 如果的确是dos格式的, 那么你可以用set ff=unix把 阅读全文
posted @ 2013-07-24 11:18 glose 阅读(266) 评论(0) 推荐(0) 编辑
摘要: http://blog.chinaunix.net/uid-25324849-id-2182916.html讲的挺详细的,记录一下~ 阅读全文
posted @ 2013-05-30 09:01 glose 阅读(267) 评论(0) 推荐(0) 编辑
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示