Algorithms
Longest Palindrome
思路: 用哈希表来计算字符出现的频率,统计偶数个字符的频率总和,出现奇数个字符时,取出其中的最大偶数,在最后的结果中加1。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| class Solution { public: int longestPalindrome(string s) { int res = 0; bool mid = false; unordered_map<char, int> m; for(int i = 0; i < s.size(); i++){ m[s[i]]++; } for (auto it = m.begin(); it != m.end(); ++it) { if (it->second % 2 == 1) { mid = true; res += it->second; res--; } else { res += it->second; } } return mid ? res + 1 : res; } };
|
Fizz Buzz
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| class Solution { public: vector<string> fizzBuzz(int n) { vector<string> res; for (int i = 1; i <= n; i++) { if (i % 3 == 0 && i % 5 ==0) { res.push_back("FizzBuzz"); }else if (i % 3 == 0) { res.push_back("Fizz"); }else if (i % 5 == 0) { res.push_back("Buzz"); }else{ res.push_back(std::to_string(i)); } } return res; } };
|
Review
本周阅读英文文章: Network Science & Threat Intelligence with Python: Network Analysis of Threat Actors/Malware Strains (Part 1)
Technique
墨迹了一周把《Effective Python》看完了,还是比较有收获的,之前在使用的时候并没有注意到相关的问题,也没有深究其中的运行机制,比如Python在执行import语句引入模块的时候,会按照深度优先的顺序执行下列操作:
1)在由sys.path
所指定的路径中,搜寻待引入的模块;
2)从模块中加载代码,并保证这段代码能够正确编译;
3)创建与该模块相对应的空对象;
4)把这个空的模块对象,添加到sys.modules
里面;
5)运行模块对象中的代码,以定义其内容。
更详细的机制在官方文档中有提到:
https://docs.python.org/zh-cn/3/reference/import.html
Share
周六去参加了百度技术沙龙,是百度安全部的技术分享,印象比较深刻的是Openrasp,通过集成到应用服务器中,能够监听各种事件,与WAF不同,Openrasp结合语义、通过Hook敏感函数等检查运行逻辑是否有变化来检测攻击,并且有详细的堆栈记录。
https://github.com/baidu/openrasp