Home

LeetCode:10.正则表达式匹配

给你一个字符串 s 和一个字符规律 p,请你来实现一个支持 ‘.’ 和 ’‘ 的正则表达式匹配。 ‘.’ 匹配任意单个字符 ‘’ 匹配零个或多个前面的那一个元素 所谓匹配,是要涵盖 整个 字符串 s的,而不是部分字符串。 示例 1: 输入:s = “aa” p = “a” 输出:false 解释:”a” 无法匹配 “aa” 整个字符串。 示例 2: 输入:s = “aa” p = “a” 输出:true 解释:因为 ‘’ 代表可以匹配零个或多个前面的那一个元素, 在这里前面的元素就是 ‘a’。因此,字符串 “aa” 可被视为 ‘a’ 重复了一次。 示例 3: 输入:s = “ab” p = “.” 输出:true 解释:”.” 表示可匹配...

Read more

出栈序列与卡特兰数

中午吃饭的时候听到隔壁桌在聊一道题,当时没想出来。 事后查了些资料,记录一下。 问题 一个栈的进栈序列为 1, 2, 3, 4, ..., n, 出栈序列有多少种情况?

Read more

KMP 字符串匹配

1 2 3 4 5 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 36 37 void preKmp(char *x, int m, int kmpNext[]) { int i, j; i = 0; j = kmpNext[0] = -1; while (i < m) { while (j > -1 && x[i] != x[j]) j = kmpNext[j]; i++; j++; if (x[i] == x[...

Read more

Bye Bye NPE

This led me to suggest that the NULL value is a member of every type, and a NULL check is required on every use of that reference variable, and it may be perhaps a billion dollar mistake. 1 – Tony Hoare What’s wrong with NULL Simply put, NULL reference (or NULL pointer) is a special marker and keyword indicating that something has no value.Pr...

Read more