casyup.me@outlook.com

0%

on my …

my solution

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
class Solution {
public:
bool isNStraightHand(vector<int>& hand, int W) {
div_t di = div(hand.size(), W);
if (di.rem) {
return false;
}

map<int, int> hds;
for (auto v : hand) {
++hds[v];
}

while (!hds.empty()) {
auto it = *hds.begin();
for (int l = it.second, b = it.first, e = it.first + W;
b < e; ++b) {
hds[b] -= l;
if (hds[b] < 0) {
return false;
} else if (hds[b] == 0) {
hds.erase(b);
}
}
}

return true;
}
};

什么也不想说 :(

the best solution

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class Solution {
public:
bool isNStraightHand(vector<int>& hand, int W) {
vector<int> v(W);

if (W == 3 && hand[0] == 2 && hand[1] == 4) {
return false;
}

for(int h: hand) {
v[h%W]++;
}

int cnt = v[0];
for(int i=0; i<W; i++) {
if(v[i] != cnt) return false;
}

return true;
}
};

虽然这个算法偷鸡(最开始那个 if 判断明显具有针对性, 在输入是 [2,4,3] 的情况下会不正确)

但是依旧对我造成了很大打击…

最开始我的算法是想了一段时间的, 怎么简单, 怎么高效.

啊… 我为何总是欠缺这种看透问题本质的能力呢…

我的算法不止返回 bool 还可以得到最后的集, 我只能如此安慰自己

emm…

网络看过了, 多线程看过了, 操作系统看过了, mysql看过了, linux看过了, 数据结构和算法也看过了…

大多需要的东西我都有看过 (虽然还需大量训练💪), 想了想, 是时候看源码了.

Read more »

Top Level Directories Means In Linux

It looks like I haven’t written some notes about Linux top-level directories. so do it now!

我好像还没写过关于 Linux 顶层文件含义的笔记, 那就现在写吧!

Read more »

聊一下大概半年前的一次误操作导致的整个服务器数据丢失的问题. 单纯分享一下, 就当看戏.
(之所以现在才说, 是怕被逮个现行… 那就尴尬了…)

Read more »

new And delete

When I was a trainee at the training institution. I was shocked when my teacher shows me the secret blow ‘new’ and ‘delete’. I still remember that day even I can’t fully understand it. It’s time to resolve it by myself!

至今我还记得在培训的时候, 讲师给我演示了 new 和 delete 的内部实现时我的震惊. 虽然当时没有完全理解. 是时候自己看看了.

Read more »

Optimization and Indexes

Indexes are used to find rows with specific column values quickly. Without an index, MySQL must
begin with the first row and then read through the entire table to find the relevant rows. The larger the
table, the more this costs. If the table has an index for the columns in question, MySQL can quickly
determine the position to seek to in the middle of the data file without having to look at all the data. This
is much faster than reading every row sequentially.

index 用于加速查询.

(PS: 就最简单来说, 索引相当于一个人的特征. 查询数据时不一定需要完全匹配, 也不一定一开始就需要完全匹配搜索, 这时候使用索引就相当于找人时使用年龄, 性别等特征来寻找一样, 是一个很简单也很重要的概念. 如何寻找并规定 index 是极其重要的一环)

Read more »