ARTS-week61

Algorithms

思路: 统计单词中的大小数量再进行判断。

Detect Capital

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Solution {
public:
bool detectCapitalUse(string word) {
int lower = 0, upper = 0;
for (int i = 0; i < word.size(); ++i) {
if (islower(word[i])) {
++lower;
} else if (isupper(word[i])) {
++upper;
if (lower > 0) {
return false;
}
}
}
return lower == 0 || upper <= 1;
}
};

Review

本周阅读英文文章:
1、Regex Performance in Python

Technique

1、找到一个无须编译,在CentOS7中就可以安装高版本Git的方法:
https://stackoverflow.com/questions/21820715/how-to-install-latest-version-of-git-on-centos-7-x-6-x

1
2
3
yum install http://opensource.wandisco.com/centos/7/git/x86_64/wandisco-git-release-7-2.noarch.rpm
yum install git
git --version

2、碰到一个MemoryError的问题,某项目抛出异常numpy.core._exceptions.MemoryError: Unable to allocate array with shape,在StarOverflow上找到类似的问题,是因为system's overcommit handling mode导致内存分配失败:
https://stackoverflow.com/questions/57507832/unable-to-allocate-array-with-shape-and-data-type

不过很费解的是我按回答中的方法,测试numpy.zeros((XXXX, XXXX), dtype='float64')是可以执行成功的,但是在代码上了实际数据就不行…考虑到服务器上还有其他程序在跑,没有去调整/proc/sys/vm/overcommit_memory的参数,建议同事先通过减少数据量解决问题。

答案中提的三个链接都是非常重要的,值得一看:
https://stackoverflow.com/questions/38688824/linux-over-commit-heuristic

https://www.kernel.org/doc/Documentation/vm/overcommit-accounting

http://engineering.pivotal.io/post/virtual_memory_settings_in_linux_-_the_problem_with_overcommit/

Share

之前朋友送了《C语言接口与实现●英文版》,但是英文太渣了,在多抓鱼上淘了中文版回来,打算对照着看~等读完了,就是第一本阅读完的英文技术书籍😁

0%