Giter Site home page Giter Site logo

suukii / 91-days-algorithm Goto Github PK

View Code? Open in Web Editor NEW
220.0 220.0 64.0 9.46 MB

91天学算法-Leetcode图解题解集合(JavaScript/C++/Python) Solutions and Explainations with Hand Drawings in Chinese(JavaScript/C++/Python)

Home Page: https://suukii.notion.site/ca5e6d9d43704a9d82e44758636642d6?v=e7bdde0a51e9424fa96b876e78b03958

JavaScript 100.00%
algorithm leetcode leetcode-cpp leetcode-cpp-solutions leetcode-javascript leetcode-python leetcode-solutions tree

91-days-algorithm's Introduction

Now is no time to think of what you do not have. Think of what you can do with what there is.

91-days-algorithm's People

Contributors

suukii avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

91-days-algorithm's Issues

打卡

class Solution {
public:
vector<vector> verticalTraversal(TreeNode root) {
vector<tuple<int, int, int>> data;
function<void(TreeNode
, int, int)> dfs = [&](TreeNode *node, int row, int col) {
if (node == nullptr) {
return;
}
data.emplace_back(col, row, node->val);
dfs(node->left, row + 1, col - 1);
dfs(node->right, row + 1, col + 1);
};
dfs(root, 0, 0);

    vector<vector<int>> ans;
    ranges::sort(data);
    int last_col = INT_MIN;
    for (auto &[col, _, val]: data) {
        if (col != last_col) {
            last_col = col;
            ans.push_back({});
        }
        ans.back().push_back(val);
    }
    return ans;
}

};


时间复杂度:O(nlogn),其中 nnn 为二叉树的节点个数。瓶颈在排序上。
空间复杂度:O(n)。

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.