Giter VIP home page Giter VIP logo

myleetcode's Introduction

记录个人刷力扣做的题目

一些心得:

  • WSL 只是写写题的话还是蛮好用的。

  • Python 里用 functools.lru_cache 进行 dp 的话要设置最大递归深度 sys.setrecursionlimit.

  • C++ 中用 lambda 捕获类内元素时,应该设置别名或者直接捕获 this.

    class MyClass {
        int idx = 0;
        void test(vector<int>& vec) {
            auto foo = [& idx = idx]() { std::cout << vec[idx] << std::endl; };
            auto bar = [&this]() { std::cout << vec[idx] << std::endl; };
        }
    }
  • 感觉 C++for_eachfor 快。

    class MyClass {
        vector<vector<int>> G;
        void foo(vector<vector<int>>& edges) {
            for_each(vec.begin(), vec.end(),
                     [& G = G](vector<int>& edge) { G[edge[0]].emplace_back(edge[1]); });
            for (vector<int>&& edge: vec)
                G[edge[0]].emplace_back(edge[1]);
        }
    }
    
  • C++push_back 要进行一次拷贝,emplace_back 不需要,但是 push_back 可以用列表初始化,而 emplace_back 只能调用构造函数,不过也因此可以不加参数。

    vector<int> foo() {
        using P = pair<int, int>;
        vector<P> vec;
        vec.push_back({0, 0});    // 通过 Vaild
        vec.emplace_back({0, 0}); // 报错 Invaild
        vec.push_back(0, 0);      // 报错 Invaild
        vec.emplace_back(0, 0);   // 通过 Vaild
        vec.push_back();          // 报错 Invaild
        vec.emplace_back();       // 通过 Vaild
        return {0, 0};            // 通过 Vaild
    }
  • C++ 中拼接字符串时用 string+=stringstream 要快。(惊了)

  • C++17 里的 string_view 是个好东西。

  • C++set 有自带的 lower_bound,返回的是大于等于而不是小于,不建议对 setstd::lower_bound.

  • C++ 中好像 bitset<32>(num).count()__builtin_popcount() 要快。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.