Contents

ARST打卡第144周[144/521]

Algorithm

lc1748_唯一元素的和

思路: 直接hash表(unordered_map)来记录出现次数,然后最后遍历hash表得出结果即可

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
class Solution {
    unordered_map<int, int> nums_count;
public:
    int sumOfUnique(vector<int>& nums) {
        int ans = 0;
        for (auto num : nums) {
            nums_count[num]++;
        }

        for (auto it : nums_count) {
            if (it.second == 1) {
                ans += it.first;
            }
        }

        return ans;
    }
};

AC之后看了答案,发现还有一个不用二次遍历的方法 链接:https://leetcode-cn.com/problems/sum-of-unique-elements/solution/wei-yi-yuan-su-de-he-by-leetcode-solutio-tueh/

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
class Solution {
public:
    int sumOfUnique(vector<int> &nums) {
        int ans = 0;
        unordered_map<int, int> state;
        for (int num : nums) {
            if (state[num] == 0) {
                ans += num;
                state[num] = 1;
            } else if (state[num] == 1) {
                ans -= num;
                state[num] = 2;
            }
        }
        return ans;
    }
};

Review

【TED演讲】如何控制你的空闲时间

人们经常说:我没有时间,所以我没有做这件事情。 实际上是因为我们不想做这些事情,所以我们没有时间。 这是目的论,而不是因果论,因为因果论更接近于事后诸葛亮。

这个视频主要讲的是,是要把自己想做的事情列好计划,并且严格执行,防止自己后面没有执行。

严格执行!!!今年虎年加油!!!

Tips

在Windows下同步linux环境和编写linux代码步骤

Share-vscode通过samba共享代码到本地开发

vscode上使用remote-ssh,并且安装很多远程插件的时候还是太占用服务器资源了

然后决定在宿主机上建立了一个samba共享目录,然后用samba共享,在本地开SI或者VScode编辑代码

缺点: 行吧…这样vscode对于系统调用的跳转应该不好用了 优点: …但是可以用上SI的灵活看到代码,也挺不错

缺点解决: https://blog.csdn.net/weixin_44624419/article/details/107928770 参考上面链接,然后改进成软链接,即可

原c_cpp_properties.json

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/usr/include/linux",
                "/usr/lib/gcc/x86_64-redhat-linux/4.8.5/include",
                "/usr/local/include",
                "/usr/include"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}

创建软链接

 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
 ⚡ 01/26|14:21:11  ~ mkdir linux_include
 ⚡ 01/26|14:21:27  ~ cd linux_include/
 ⚡ 01/26|14:21:29  linux_include ln -s /usr/include/linux/ linux
 ⚡ 01/26|14:22:15  linux_include ls
linux
 ⚡ 01/26|14:22:16  linux_include ll -a
总用量 4.0K
drwxr-xr-x  2 root root   19 1月  26 14:22 .
dr-xr-x--- 13 root root 4.0K 1月  26 14:22 ..
lrwxrwxrwx  1 root root   19 1月  26 14:22 linux -> /usr/include/linux/
 ⚡ 01/26|14:22:19  linux_include ln -s /usr/lib/gcc/x86_64-redhat-linux/4.8.5/include/ gcc4.8.5_include
 ⚡ 01/26|14:22:46  linux_include ln -s /usr/local/include/ usr_local_include
 ⚡ 01/26|14:23:07  linux_include ln -s /usr/include/ usr_include
 ⚡ 01/26|14:23:20  linux_include ll
总用量 0
lrwxrwxrwx 1 root root 47 1月  26 14:22 gcc4.8.5_include -> /usr/lib/gcc/x86_64-redhat-linux/4.8.5/include/
lrwxrwxrwx 1 root root 19 1月  26 14:22 linux -> /usr/include/linux/
lrwxrwxrwx 1 root root 13 1月  26 14:23 usr_include -> /usr/include/
lrwxrwxrwx 1 root root 19 1月  26 14:23 usr_local_include -> /usr/local/include/
 ⚡ 01/26|14:23:20  linux_include ln -s /usr/bin/gcc linux_gcc
 ⚡ 01/26|14:24:11  linux_include ll
总用量 0
lrwxrwxrwx 1 root root 47 1月  26 14:22 gcc4.8.5_include -> /usr/lib/gcc/x86_64-redhat-linux/4.8.5/include/
lrwxrwxrwx 1 root root 19 1月  26 14:22 linux -> /usr/include/linux/
lrwxrwxrwx 1 root root 12 1月  26 14:24 linux_gcc -> /usr/bin/gcc
lrwxrwxrwx 1 root root 13 1月  26 14:23 usr_include -> /usr/include/
lrwxrwxrwx 1 root root 19 1月  26 14:23 usr_local_include -> /usr/local/include/

修改c_cpp_properties.json

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "Z:\\linux_include\\linux",
                "Z:\\linux_include\\gcc4.8.5_include",
                "Z:\\linux_include\\usr_local_include",
                "Z:\\linux_include\\usr_include"
            ],
            "defines": [],
            "compilerPath": "Z:\\linux_include\\linux_gcc(上网学,配置成windows安装的gcc)",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}
无法使用 compilerPath 解析配置:“Z:\linux_include\linux_gcc”

windows无法使用Unix的运行程序,所以还是得自己在本地装一个gcc(网上有很多教程),但是由于我不在本地编译 现在已经能代码跳转系统库了,所以不折腾了

软链接无法访问

尴尬发现samba共享目录的软链接无法访问…….

注: 可以用man smb.conf去查看配置的含义

然后设置如下 编辑/etc/samba/smb.conf

1
2
3
4
5
6
[global]
unix extensions = no

[share]
follow symlinks = yes
wide links = yes

注意:如果您使用的是samba的较新版本,则可以使用以下命令:

1
2
3
4
5
6
[global]
allow insecure wide links = yes

[share]
follow symlinks = yes
wide links = yes

pkill -1 smbd

如果你是docker,你用docker宿主机启动的samba共享,然后在docker内部创建的软链接,只能访问到宿主机对应的位置…而不是docker内的位置 所以还是要在docker内启动一个samba

自己装samba
1
2
3
4
5
6
7
8
yum install samba
 ⚡ 01/26|15:11:04  linux_include useradd root
 ⚡ 01/26|15:11:58  linux_include smbpasswd -a root
New SMB password:
Retype new SMB password:
Added user root.

systemctl start smb

/etc/samba/smb.conf

 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
## See smb.conf.example for a more detailed config file or
## read the smb.conf manpage.
## Run 'testparm' to verify the config is correct after
## you modified it.

[global]
        workgroup = SAMBA
        security = user
        log file = /var/log/smbd.log
        max log size = 0

        passdb backend = tdbsam

        printing = cups
        printcap name = cups
        load printers = yes
        cups options = raw
        unix extensions = yes
        follow symlinks = yes
        hosts allow = *
        smb ports = 139
        ## host msdfs = yes
        allow insecure wide links = yes

[root]
        comment = workspace
        path = /root
        vfs objects = aio_pthread
        aio_pthread:aio open = yes
        writeable = yes
        map archive = no
        follow symlinks = yes
        wide links = yes
        valid users = root
        write list = root