Giter Club home page Giter Club logo

leetcodeexample's Introduction

Length Of Longest Substring

Sliding Window

  1. 不同字元

    • 加長window(右邊指標+1)
    • 紀錄目前字串長度
  2. 相同字元

    • 刪除左邊指標的字元,直到左右邊字元相同

基本做法

  • 利用dictionary儲存目前字串
  • 如果char已經出現過,和之前的字串長度做比較,儲存最大值
  • 索引起始點定位成這次char的位置,下次迴圈將char的下一個位置開始執行
  • 避免字串完全沒重複,回傳答案之前再比一次
  • 因為每一次遇到重複char,就要以那個char為起點重跑一次迴圈,所以效率低

ValidParentheses

  • 遇到左括號就push
  • 遇到又括號就 TryPop
  • 如果左右括號都match的話,stack應該為空

TwoNumber

思路

  1. 要注意的就是list1跟list2長度可能不一樣
  2. 相加後可能比9還大,需要考慮進位的情況

解題方法

  1. 迴圈
  • 要運用傳址呼叫的技巧,一開始讓point只給要回傳的結果,之後把下一個節點只給point,讓point前進 。
  1. 遞迴
  • 停止條件 l1 l2為空,而且沒有進位。
  • l1和l2相加後,將兩列node和進位結果傳入遞迴呼叫。

Two Sum

思路

  1. 陣列無限大,回傳第一個組合即可
  2. 製作索引的同時也要比較是否有符合條件的配對

解題方法

  1. 雙重迴圈
  • 時間複雜度O(n^n)
  1. 單迴圈
  • 用target減去陣列數字選出對應的候選數字
  • 當候選數字出現時,回傳候選數字位址當下數字位址
  • 記錄陣列每個數字的值和位址

leetcodeexample's People

Watchers

Robbin Hsu 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.