763. Partition Labels - Medium 前往題目 想法 每個字母的第一個和最後一個為區間 思路 記錄每個字母的最後一位的位置 開始循環s,每次更新當前的最後一位在哪,取最遠的(因為最大區間不能被切開,否則會有同個字母分隔兩邊的情況) 遇到盡頭時(當前字母最後一位與最遠的同位),切開並記錄 這題是把每個字母都當區間來看,只是開頭並不重要,重要的是每個字母最後在哪裡出現,因為不能在中途就切開,不然就會出現同個字母被切開的情況,這也是題 2025-03-30 Leetcode > Medium #Leetcode #心得 #String #Two Pointers #Greedy #Hash Table
2780. Minimum Index of a Valid Split - Medium 前往題目 想法 先找出最多的那個元素,然後迭代的時候再算其元素在左邊以及右邊各有多少 思路就和我的想法一樣,不過最後我忘了除二或乘二去正確判斷超過半數 Codeclass Solution { public int minimumIndex(List<Integer> nums) { int[] dominant = new int[] 2025-03-27 Leetcode > Medium #Leetcode #心得 #Array #Hash Table #Sorting
Shell基礎筆記 - The Missing Semester of Your CS Education 可惜還是學生的時候不知道有這門好課,雖然已經有些經驗了,但還是想看看這門課能帶給我什麼新東西 快速複習Basics of the Shell Shell = text-based interface for executing commands. Bash (Bourne Again Shell) is widely used. Basic Commands date → Show 2025-03-26 電腦科學 > The Missing Semester of Your CS Education #shell #the-missing-semester-of-your-cs-education
2033. Minimum Operations to Make a Uni-Value Grid - Medium 前往題目 想法 中位數應該是最靠近所有數字的數 思路 把陣列扁平化,因為位置資訊不重要 扁平化後就可以排序並找到中位數 接著計算步數 只有當前數字減去中位數後,不能以每次x的步伐走到中位數才是invalid的狀況 Codeclass Solution { public int minOperations(int[][] grid, int x) { 2025-03-26 Leetcode > Medium #Leetcode #心得 #Array #Math #Matrix #Sorting
3394. Check if Grid can be Cut into Sections - Medium 前往題目 想法 不知該如何檢查是否可切成三塊 思路看成是intervals來解 分成x和y座標並排序 垂直和水平方向分開來檢查是否重疊,並記錄不重疊數 輸出結果 Code class Solution { public boolean checkValidCuts(int n, int[][] rectangles) { int[][] x = 2025-03-25 Leetcode > Medium #Leetcode #心得 #Array #Sorting
如何使用python的venv 當python有問題的時候直接使用venv通常都能解決,甚至每個專案都用venv是最好的,這樣就可以把package分開 要先安裝python3-venv,例如Linuxsudo apt install python3-venv 建立venv目錄python3 -m venv venv 進入venv環境source venv/bin/activate 然後就可以自由安裝套件了,注意每次要安裝都須 2025-03-24 綜合 #venv #python
3169. Count Days Without Meetings - Medium 前往題目 想法 最直觀的就是用set裝滿天數,然後用所有的meetings去排除,最後看size,但很明顯的這太慢了,每個區間有n天,然後有n個區間,就要n^n次了 思路 先依照starting day排序 然後檢查每個區間是否和上一個重疊 是就合併,否則紀錄天數 最後天數減去總天數就是答案 Code網友解答 class Solution { public int coun 2025-03-24 Leetcode > Medium #Leetcode #心得 #Array #Sorting
macos如何轉換java的JDK版本 安裝JDK之後檢查一下,應有兩個版本/usr/libexec/java_home -V export JAVA_HOME=`/usr/libexec/java_home -v 欲切換的版本` 3.java -version檢查一下是否切換成功 參考 2025-03-21 綜合 #macos #java #jdk
3191. Minimum Operations to Make Binary Array Elements Equal to One I - Medium 前往題目 想法 或許可以用sliding window但對於如何判斷是否應該翻轉bit毫無想法 思路運用Greedy概念,只需要專注在當前的數字,0就翻轉,否則不管,如果valid最後一定全部都是1,否則會有一或兩個0 三個為一個window,第一個為基準判斷是否翻轉 每次翻轉紀錄次數 結束後,如果最後兩位有1或2個0就是invalid 對於如何確定這是可行的並不清楚…但應該可以看作是每次 2025-03-19 Leetcode > Medium #Leetcode #心得 #Queue #Array #Bit Manipulation #Sliding Window #Prefix Sum
2401. Longest Nice Subarray - Medium 前往題目 想法 忘了有sliding window:D太久沒寫了 思路關鍵是紀錄哪些bit已經被使用,以及利用sliding window鎖定範圍 Code網友解答 class Solution { public int longestNiceSubarray(int[] nums) { int usedBits = 0, l = 0, res = 2025-03-18 Leetcode > Medium #Leetcode #心得 #Array #Bit Manipulation #Sliding Window