Git Product home page Git Product logo

leetcode-practice's Introduction

Todo

  • stack
84. Largest Rectangle in Histogram
  • sliding window
239. Sliding Window Maximum.py

Retry Todo

  • Arrays & Hashing
238. Product of Array Except Self
  • Two Pointer
42. Trapping Rain Water
11. Container With Most Water
15. 3Sum
  • Sliding Window
3. Longest Substring Without Repeating Characters
424. Longest Repeating Character Replacement
567. Permutation in String
76. Minimum Window Substring
239. Sliding Window Maximum
  • Stack
155. Min Stack
22. Generate_Parentheses
853. Car Fleet
  • Binary Search
74. Search a 2D Matrix
875. Koko Eating Bananas
33. Search in Rotated Sorted Array
981. Time Based Key-Value Store
4. Median of Two Sorted Arrays
  • Linked List
21. Merge Two Sorted Lists
206. Reverse Linked List
143. Reorder List
19. Remove Nth Node From End of List

leetcode-practice's People

Contributors

fionn88 avatar

Watchers

 avatar

leetcode-practice's Issues

22. Generate_Parentheses Problem

Time Complexity:O(n^2)
Space Complexity:O(1)
Approach 1:Generate all possible combinations of parentheses using a recursive backtracking approach.
Q: Why does this generate all possible combinations?

class Solution:
    def generateParenthesis(self, n: int) -> List[str]:
        result = []
        def backtrack(s, left, right):
            # Check the validity of parentheses.
            if len(s) == 2 * n:
                result.append(s) 
                return
            if left < n:
                backtrack(s + '(', left + 1, right)
            if right < left:
                backtrack(s + ')', left, right + 1)
        # Starting from an empty string, recursively add left and right parentheses.
        backtrack('', 0, 0)
        return result

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.