Simon Lai's Blog
  • 首頁
  • 歸檔
  • 分類
  • 標籤
  • 關於

1396. Design Underground System - Medium

前往題目 想法 用OOP解 思路 乘客class,紀錄checkin和checkout時間地點 路線class, 紀錄起站終站以及總共花費時間和次數 用Map把id和乘客連接起來,路線和路線class連接起來 checkin:把乘客資訊加入即可 checkout:把乘客checkout,更新或加入路徑,最後移除乘客資訊,因為checkout了 average:直接找到該路徑,然後調用路徑cl
2024-03-28
Leetcode > Medium
#Leetcode #心得 #String #Hash Table #Design

1603. Design Parking System - Easy

前往題目 想法 直接陣列存 思路 定義一個陣列,放上每個size的車格剩多少 加入車輛的時候如果遇到該車格已經沒了就直接回傳false 否則就加入車輛,此時要把對應車格減1 Codeclass ParkingSystem { int[] park; public ParkingSystem(int big, int medium, int small) {
2024-03-28
Leetcode > Medium
#Leetcode #心得 #Simulation #Design #Counting

104. Maximum Depth of Binary Tree - Easy

前往題目 之前寫的文章 思路這題有好多種寫法,光是DFS就可以寫成幾個不同的樣子 邊走邊紀錄深度 Code自己寫的 class Solution { int res = 1; public int maxDepth(TreeNode root) { if (root == null) return 0;
2024-03-23
Leetcode > Easy
#Leetcode #心得 #Binary Tree #Depth-First Search #Breadth-First Search #Tree

5. Longest Palindromic Substring — Medium

前往題目 之前寫的文章 思路 2 pointers 每個index都當是中心點向左右擴散 奇偶分開處理 Codeclass Solution { public String longestPalindrome(String s) { int resL = 0, resR = 0; int resLen = resR - resL +
2024-03-23
Leetcode > Medium
#Leetcode #心得 #String #Dynamic Programming

705. Design HashSet - Easy

前往題目 想法 和hashmap異曲同工之妙 思路簡單版:和hashmap那題一樣用同樣大小的array 進階版:也和hashmap那題一樣,用ListNode和chaining Code簡單版 class MyHashSet { boolean[] set; public MyHashSet() { set = new boolean[
2024-03-22
Leetcode > Easy
#Leetcode #心得 #Array #Hash Table #Linked List #Design #Hash Function

706. Design HashMap - Easy

前往題目 想法 key-value,key是唯一的,那能用hashset嗎?題目說不能用built-in hash table,hashset算hash table嗎?維基:In computing, a hash table, also known as a hash map or a hash set,所以不能用hash set 那是要手動運算hashcode? 不用hash table又想
2024-03-22
Leetcode > Easy
#Leetcode #心得 #Array #Hash Table #Linked List #Design #Hash Function

523. Continuous Subarray Sum

前往題目 想法 the sum of the elements of the subarray is a multiple of k: 判斷是否整除就好 思路又是一題大家都說沒寫過怎麼可能在面試寫出來的題目😂 關鍵是建立prefixSum map,prefix sum -> index 先加入0, -1到map裡,防止遇到0就以為是答案的edge case,因為至少要2個數字組合起來
2024-03-21
Leetcode > Medium
#Leetcode #心得 #Array #Math #Hash Table #Prefix Sum

1929. Concatenation of Array - Easy

前往題目 想法 串接起來就好 思路 疊代新的陣列(原始的兩倍),並使用index變數來紀錄目前循環到哪個 每次判斷index是否出界了,出界後歸0 否則+1 Codeclass Solution { public int[] getConcatenation(int[] nums) { int[] res = new int[nums.length
2024-03-21
Leetcode > Easy
#Leetcode #心得 #Array #Simulation

第一次開發VSCode Extension之流程與心得

前置作業 VSCode Nodejs,可安裝nvm隨意切換與安裝不同版本 Git 初始化專案使用Yeoman來初始化擴展專案 npm install --global yo generator-code yo code Yeoman導覽會帶你一步一步建立專案 設定好一些專案的詳細資訊後就可以開始寫code了! 一些基本文件介紹 F5可以進入debug模式,測試擴展 .vscode資料夾存放程
2024-03-20
Project > VSCode
#VSCode Extension #TypeScript #Npm #Git

1461. Check If a String Contains All Binary Codes of Size K - Medium

前往題目 想法 全部比較一遍?這樣需要$O(2^k \times n \times k)$,太沒效率了 思路 疊代整個s,每次切大小k並嘗試加入Set 利用Set的特性,如果可以在s中找到至少$2^k$個unique element,就代表一定是true Code class Solution { public boolean hasAllCodes(String s,
2024-03-20
Leetcode > Medium
#Leetcode #心得 #String #Hash Table #Bit Manipulation #Hash Function #Rolling Hash
1…1516171819…36

搜尋

Hexo Fluid