Giter Club home page Giter Club logo

leetcode_75_python's Introduction

Array

  1. Merge Strings Alternately
  • find min, loop over string and add the rest using res.append([word1[min:], word[min:]])
  1. GCD of string
  • loop min(len1,len2), 0, -1 -> check if its a valid gcd | valid gcd -> if len1, len2 is divisible and base * n1 = str1, base * n2 = str2

Two Pointers

  1. Move all zeros to end
  • loop over array, maintain pointer for zeros. for each non-zero, swap the array and increment the zeroPtr
  1. Is SubSequence
  • loop over main string, maintain pointer for matching chars, if s[ptr] == t[i] => ptr += 1, return true if ptr == len(s)
  1. Container water distance
  • left and right index of array, calc current area and maintain gobal area max for each step. and update the idx based on max left and righ value

BT - DFS

  1. find max depth of the Tree
  • recursive -> return 1 + max(self.maxDepth(left), self.maxDepth(right))
  • iter -> use stack to store node and depth, find max(depth) and add child to stack
  1. check leaf similarity of two tree
  • calc leaf using dfs find_leaf(node, leaf) -> if not node.left and not node.right -> leaf.append(node.val) find_leaf(node.left, leaf) find_leaf(node.right, leaf)
  1. good nodes
  • use dfs with recursive and keep track of maxValue. return the good nodes

BT - BFS

  1. right side view of tree
  • use queue with node and level, and maintain previous_level. while traversing if not level != previous_level and add to res, add right to queue before left
  1. max level sum
  • with queue, maintain maxsum, res, inside while queue: loop through all element [which is the current level]. calc maxSum and currSum

BST

  1. Search BST
  • general bst search using recursion

leetcode_75_python's People

Contributors

karthi07 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.