Go最全【LeetCode刷题日记】71(5),Golang开发避坑指南

img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上Go语言开发知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

如果你需要这些资料,可以戳这里获取

[外链图片转存中…(img-5c4J9Ixm-1641480644397)]

C

char \*\* split(const char \* s, char delim, int \* returnSize) {
    int n = strlen(s);
    char \*\* ans = (char \*\*)malloc(sizeof(char \*) \* n);
    int pos = 0;
    int curr = 0;
    int len = 0;
    
    while (pos < n) {
        while (pos < n && s[pos] == delim) {
            ++pos;
        }
        curr = pos;
        while (pos < n && s[pos] != delim) {
            ++pos;
        }
        if (curr < n) {
            ans[len] = (char \*)malloc(sizeof(char) \* (pos - curr + 1)); 
            strncpy(ans[len], s + curr, pos - curr);
            ans[len][pos - curr] = '\0';
            ++len;
        }
    }
    \*returnSize = len;
    return ans;
}

char \* simplifyPath(char \* path){
    int namesSize = 0;
    int n = strlen(path);
    char \*\* names = split(path, '/', &namesSize);
    char \*\* stack = (char \*\*)malloc(sizeof(char \*) \* namesSize);
    int stackSize = 0;
    for (int i = 0; i < namesSize; ++i) {
        if (!strcmp(names[i], "..")) {
            if (stackSize > 0) {
                --stackSize;
            } 
        } else if (strcmp(names[i], ".")){
            stack[stackSize] = names[i];
            ++stackSize;
        } 
    }
    
    char \* ans = (char \*)malloc(sizeof(char) \* (n + 1));
    int curr = 0;
    if (stackSize == 0) {
        ans[curr] = '/';
        ++curr;
    } else {
        for (int i = 0; i < stackSize; ++i) {
            ans[curr] = '/';
            ++curr;
            strcpy(ans + curr, stack[i]);
            curr += strlen(stack[i]);
        }
    }
    ans[curr] = '\0';
    for (int i = 0; i < namesSize; ++i) {
        free(names[i]);
    }
    free(names);
    free(stack);
    return ans;
}

C++

class Solution {
public:
    string simplifyPath(string path) {
        auto split = [](const string& s, char delim) -> vector<string> {
            vector<string> ans;
            string cur;
            for (char ch: s) {
                if (ch == delim) {
                    ans.push\_back(move(cur));
                    cur.clear();
                }
                else {
                    cur += ch;
                }
            }
            ans.push\_back(move(cur));
            return ans;
        };

        vector<string> names = split(path, '/');
        vector<string> stack;
        for (string& name: names) {
            if (name == "..") {
                if (!stack.empty()) {
                    stack.pop\_back();
                }
            }
            else if (!name.empty() && name != ".") {
                stack.push\_back(move(name));
            }
        }
        string ans;
        if (stack.empty()) {
            ans = "/";
        }
        else {
            for (string& name: stack) {
                ans += "/" + move(name);
            }
        }
        return ans;
    }
};

C++

class Solution {
public:
    string simplifyPath(string path) {
        deque<string> st;
        int n = path.size(), i = 0;
        while(i < n){
            if(i < n && path[i] == '/') i++;
            else{
                string temp;
                while(i < n && path[i] != '/') temp += path[i++];
                if(temp == ".." && !st.empty()) st.pop\_back();
                else if(temp != ".." && temp != ".") st.push\_back(temp); 
            }
        }
        string res = "/";
        while(!st.empty()){
            res += st.front() + "/";
            st.pop\_front();
        }
        if(res.size() > 1) res.pop\_back();
        return res;
    }
};


![img](https://img-blog.csdnimg.cn/img_convert/8d39c308e454b7da5ad6c2d0f278dc7c.png)
![img](https://img-blog.csdnimg.cn/img_convert/cb814459054b367fe27f9c8fee5bd251.png)
![img](https://img-blog.csdnimg.cn/img_convert/e8e2f54c5fd11bb98e881c9459aedd46.png)

**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上Go语言开发知识点,真正体系化!**

**由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新**

**[如果你需要这些资料,可以戳这里获取](https://bbs.csdn.net/topics/618658159)**

深入学习提升的进阶课程,涵盖了95%以上Go语言开发知识点,真正体系化!**

**由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新**

**[如果你需要这些资料,可以戳这里获取](https://bbs.csdn.net/topics/618658159)**

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值