Giter Site home page Giter Site logo

leetcode's Introduction

leetcode

刷题 使用git

  • 判断一个链表是否为回文结构

准备一个栈,遍历链表到栈中,从栈中弹出,和链表一一比较,相同则是回文。

  • 荷兰国旗问题可以用去优化快排算法。

因为荷兰国旗问题中间是一堆数确定了位置,而普通的partition只确定了一个位置。

  • 自己写一下二叉树的寻找后继节点问题(前驱节点也就类似)。

在初级5 70分钟

  • 怎么判断一颗树是否是完全二叉树。

要用层次遍历来,遍历的每个节点都必须顺序经过一下两个判断。 (1)该节点只有右节点没有左节点,直接返回false。 (2)该节点如果是子结点数不全的情况(只有左节点或没有节点),接下来遍历的所有节点都必须是叶节点,否则返回false。(自己画一下图看看,逻辑是这个逻辑,但是不好想。)

  • 求一颗完全二叉树的节点个数,要求时间复杂度小于O(N)。初级5 170分钟

先遍历最左节点算出这棵树的总高度h,再求出根节点的右子树的高度,如果等于h, 则左子树为满二叉树,用2^n - 1即为左子树的节点数,再+1就算上了根节点,接下来 只要递归右子树即可。(算法一样) 如果右子树的高度小于h,说明左子树不满,但是右子树是满的,右子树的节点数为2^n - 1, 一样可以求,接着只需要递归左子树即可。

leetcode's People

Contributors

lzq127001 avatar

Watchers

 avatar

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.