0%

题目

Given a non-empty string check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. You may assume the given string consists of lowercase English letters only and its length will not exceed 10000.

Example 1:

Input: "abab"
Output: True
Explanation: It's the substring "ab" twice.  

Example 2:

Input: "aba"
Output: False 

Example 3:

Input: "abcabcabcabc"
Output: True
Explanation: It's the substring "abc" four times. (And the substring "abcabc" twice.)  

思路

start : 代表要比较的子串的开始索引

length : 代表当前的字串长度, length最多为str.length()/2长度,而且还得是偶数字节

循环不定式
如果duplicate的length [1, str.length()/2]

那么我们可以实时得到默认的子串个数就是 str.length() / length = compare_times

这样就是说我们要比较compare_times次,其中每一次比较要比较length长度

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
32
33
34
35
class Solution {
public:
bool repeatedSubstringPattern(string s) {
int len = 1, start=0, cmp_times=0;
for(int len = 1; len <= (floor)(s.length() / 2); ++len)
{
if(s.length() % len != 0)
continue;
cmp_times = s.length() / len;
bool bCurDup = true;
for(int i=1; i<cmp_times; ++i)
{
if(bCurDup == true)
for(int j=0; j<len; ++j)
{
if(s[j] != s[i*len+j])
{
bCurDup = false;
break;
}
}
else
{
break;
}
}
if(bCurDup == true)
{
return true;
}
}

return false;
}
};

1 numpy

1.1 如何创建array

创建array的几种方式

  • numpy.array()

    An array, any object exposing the array interface, an object whose

          __array__ method returns an array, or any (nested) sequence
  • numpy.asarray()

    array_like

          Input data, in any form that can be converted to an array.  This
          includes lists, lists of tuples, tuples, tuples of tuples, tuples
          of lists and ndarrays.
  • 自动生成数组 numpy.arange numpy.logspace numpy.linspace 用于创建等差 等比 array(arange和linspace创建等差array的方式有区别)

  • numpy.full numpy.zeros numpy.ones

  • numpy.fromstring numpy.frombuffer numpy.from function

1.3 存取元素

Read more »

前言

我们都知道在高级语言中都有异常处理语法(C没有语法,但有异常处理,不过这是程序员在代码层面自己实现的),今天我们来讨论异常处理机制。

首先,我们来看CppCon 2019上Ben Saks关于Exception的演讲。

Read more »

最近在学习memory order,越学习越深,网上有介绍一本资料《A Primer on Memory Consistency and Cache Coherence》,本来想直接下载,发现csdn就是恶心,明明是盗版,结果还要自己花钱下载。结果,发现这书2020年2月出了第二版,找到了出版社的网站,但是下载不了。柳岸花明,在IEEE Xplore里找到了,但没办法下载,需要学校帐号。
在网上又找到了一个下载IEEE Xplore的方法,保存一下

  1. 找到某篇文章:
    https://ieeexplore.ieee.org/document/7965747

  2. 查询到DOI是:

  3. 1109/SERA.2017.7965747

  4. http://sci-hub.tw
    输入10.1109/SERA.2017.7965747即可下载pdf

在用CMake构建程序的时候,经常要用到find_package来查找库,那么什么样的库可以被find_package找到呢?

  • ldconfig -p | grep libjpeg

  • locate libGL.so

  • pkg-config

    pkg-config –cflags jpeg
    pkg-config –libs jpeg
    pkg-config –cflags “jpeg >= 1.0.0” # for version check
    pkg-config –modversion jpeg | awk -F. ‘{ printf “0x%02X%02X%02X\n”,$1,$2,$3 }’ #version check

  • dpkg -s packagename (deb-based distribution)

1 前言

在Windows平台,我们的exe dll 都是PE格式,在Linux平台是ELF格式(x86/arm等)。

那种格式可以被OS识别甚至加载、启动都与OS息息相关。

我一直有个疑问,就是为什么Windows 64位系统上可以跑32位应用,app可以同时跑在macos 32/64上?
这两个,一个是OS问题,一个是硬件平台指令集问题。现在Windows arm上也可以跑x86应用。那么导致这些结果的原因是什么呢?

首先说Apple,使用的是一种叫做Fat Binary的技术,也就是我在编译程序的时候里面其实有包含了两套代码,同时支持x86/64,苹果现在宣布今后将把macos从x86迁移到arm平台,那么是要还是用Fat Binary技术吗?Fat Binary的优点和缺点都显而易见,那么还有其它方式吗?

我们知道,Windows系统,32位应用可以在64位系统上运行,64位程序不能在32位系统上运行,这是为什么?

ToDoList

Read more »

题目

Given two binary search trees root1 and root2.

Return a list containing all the integers from both trees sorted in ascending order.

Example 1:

Input: root1 = [2,1,4], root2 = [1,0,3]
Output: [0,1,1,2,3,4]

Example 2:

Input: root1 = [0,-10,10], root2 = [5,1,7,0,2]
Output: [-10,0,0,1,2,5,7,10]  

Example 3:

Input: root1 = [], root2 = [5,1,7,0,2]
Output: [0,1,2,5,7]  

Example 4:

Input: root1 = [0,-10,10], root2 = []
Output: [-10,0,10]  

Example 5:

Input: root1 = [1,null,8], root2 = [8,1]
Output: [1,1,8,8]  
Read more »

参考资料 我们为什么需要反码和补码?

大学在C语言课上,第一次接触原码、反码、补码,觉得很奇怪,我们用二进制表示,然后直接加减乘除就好了。要搞明白这些码,要从二进制开始。

人类钟意于十进制的历史,有人说是因为10个手指头(也可能是10个脚趾头,手动狗头),阿拉伯人改进了印度的十进制,后来传到了欧洲,后面变成世界标准。

人类习惯了十进制,但电子设备有自己的角度,就像那些动物如果没有10根手指,大概率也不会产生10进制,而是会产生比如20进制,12进制。

二极管是人类最开始发明的比较简单的电子元器件,这里面只有开 关两种状态,这也是我们采用二进制的原因,当然现在电子元器件可以有三种状态,但标准已经制定完了,再换成三进制的代价太大了。

二进制也可以进行加减运算啊,为什么要设计这么多码,这一切都是因为我们CPU中只有加法器。加法器可以实现加减乘除的运算,同时用电路实现减法器 乘法器 除法器都非常复杂,既然可以用加法来实现所有的加减乘除操作,那么从成本考虑只保留了加法器。

既然我们选择了省钱,那么就要做好在另一个方面复杂度提高的心理准备,“好快省”是不可能同时存在的,我们要尊重科学规律、自然规律。

Read more »