摘要: 号称还有O(n)的算法: http://articles.leetcode.com/longest-palindromic-substring-part-ii/ 后面再研究, 阅读全文
posted @ 2017-09-02 23:43 nosaferyao 阅读(115) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution { 2 public: 3 int lengthOfLongestSubstring(string s) { 4 vector signs(256, -1); 5 int max_length = 0; 6 int last_valid = -1; 7 for (size_t ... 阅读全文
posted @ 2016-09-06 22:19 nosaferyao 阅读(148) 评论(0) 推荐(0) 编辑
摘要: 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListNode(int x) : val(x), next(NULL) {} 7 * }; 8 */ 9 10 void ad... 阅读全文
posted @ 2016-09-06 21:29 nosaferyao 阅读(166) 评论(0) 推荐(0) 编辑
摘要: 今天先熟悉熟悉, 希望后面能一次就过 1 #include 2 #include 3 4 using namespace std; 5 6 bool mycompare(const pair&a, const pair& b) 7 { 8 return a.first twoSum(vector& nums, int target) { 14 v... 阅读全文
posted @ 2016-09-06 20:31 nosaferyao 阅读(155) 评论(0) 推荐(0) 编辑
摘要: hadoop 中使用perl的时候, 坑太多了。先列举一下, 以后hadoop中能不使用perl, 就不使用perl了。 (1) chomp在读数据循环的时候, 常常会这样去除空格while(<STDIN>){ chomp; .........}问题在哪里?如果从标准读入的数据格式为: "*\t\t\t\n". 那么chomp会把 后面的 \t 也个清空了, 后面在使用的时候, 就会发生错误。(2) warning信息如果你的perl程序中使用了 using warnings, 那么恭喜你, 你的程序可能会把整个集群搞挂。为什么会这样呢?比如:在输出的时候, 使 阅读全文
posted @ 2012-10-19 16:46 nosaferyao 阅读(422) 评论(0) 推荐(0) 编辑
摘要: 文章来自于:http://www.flatws.cn/article/program/shell/2010-08-26/10767.htmlBash shell中的位置参数$#,$*,$@,$0,$1,$2...及特殊参数$?,$-等的含义在Bash shell中经常会见到一些比较特殊的符号,本人现收集与此,以供查阅:位置参数:详见ABS(Advanced Bash Shell)中文翻译版103页第9章第一节内部变量,当然英文版ABS都一样啦$0, $1, $2,等等...位置参数,从命令行传递给脚本,或者是传递给函数.或者赋职给一个变量.(具体见Example 4-5 和Example 11 阅读全文
posted @ 2012-10-11 15:59 nosaferyao 阅读(183) 评论(0) 推荐(0) 编辑
摘要: 读入的时候, 和期待的原始文件还是不一样的。当我们使用 hadoop fs -text 打印 sequence file的时候, 会发现打印的格式是:num"\t"data 这样的格式。在使用 streaming 读入 sequence file 设置: -inputformat org.apache.hadoop.mapred.SequenceFileAsTextInputFormat的时候, 读入的数据的格式也是这样的。在使用的时候, 需要注意一下。 阅读全文
posted @ 2012-10-06 11:00 nosaferyao 阅读(465) 评论(0) 推荐(0) 编辑
摘要: 1, 选定列选择列的起始位置处, 然后 ctrl + v2, 选定列后操作选择列的起始位置处, 然后 ctrl + v , 然后操作:比如删除:d, 替换, r+替换的内容, 其他类似3, 选定列后插入选择列的起始位置处, 然后 ctrl + v , shift+i, 输入完以后, esc两下。 阅读全文
posted @ 2012-09-13 20:20 nosaferyao 阅读(316) 评论(0) 推荐(0) 编辑
摘要: 最近项目中需要使用perl 的url encode和decode功能。以前一直使用正则表达式的版本, 当然也是从别的地方弄过来的。 结果里面一个严重的bug, 害我不浅啊。sub my_encode{ my $str = shift; $str =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($str))/seg; return $str;}print &my_encode("2%3A1");这个出来的结果是:2%323A1, 期望的结果是: 2%253A1回归到最原始, use URI::Escape;pri 阅读全文
posted @ 2012-08-24 17:30 nosaferyao 阅读(717) 评论(0) 推荐(0) 编辑
摘要: 限制是:不能有连续的0, 1可以连续, 问拼成长度为k的串, 可能有多少个。 方法f0(n)表示长度为n的串, 结尾为0,符合上述要求的不同字符串个数f1(n)表示长度为n的串, 结尾为1,符合上述要求的不同字符串个数那么f(n) =f0(n) +f1(n), 明显 f1(n) = f1(n-1) + f0(n-1), f0(n) = f1(n-1),于是 f(n) =f1(n-1) + f0(n-1) +f1(n-1) = 2 *f1(n-1) + f0(n-1)可以使用动态规划计算。也可以只求 f1(k)。 阅读全文
posted @ 2012-08-17 18:33 nosaferyao 阅读(132) 评论(0) 推荐(0) 编辑