/* 自定義代碼塊樣式 */
Herr Deng桑的教學blog
這是Herr Deng桑的教學blog,主要處理作業與班導事務,另外還有數位小品。
網頁
首頁
密碼學
程式設計Programming
APP
計算機概論
herrDeng網內搜尋
自訂搜尋
Ads
2024年8月2日 星期五
Python C++ sliding windows解Leetcode 2134 Minimum Swaps to Group All 1'...
Python C++ sliding windows解Leetcode 2134 Minimum Swaps to Group All 1's Together II
使用sliding window, 由於陣列是循環的,所以右邊的游標r應該一直走到n+n0或n+n1
[Python code請進]
-----
按我讀文 »
2024年7月26日 星期五
C++Floyd Warshall解Leetcode 1334 Find the City With the Smallest Number ...
C++Floyd Warshall解Leetcode 1334 Find the City With the Smallest Number of Neighbors at a Threshold
由於每對 (i, j) 都有許多最短路徑需要計算,採用 Floyd-Warshall 演算法比較划算。
---
按我讀文 »
2024年7月24日 星期三
Python C++速解排序問題Leetcode 2191 Sort the Jumbled Numbers
今日Leetcode的排序問題2191. Sort the Jumbled Numbers,主要有兩個部份,一個是把數字轉成另一個數字,用int就行,採Least Significant Digit First。然後排序,不建議用自訂Lambda,跑能過但非常慢;更不建議自製車輪去排序。比較快的方式是sort ((mapping(x), index),然後再從排序後的資料中取得 x
[Python code請進]
按我讀文 »
2024年7月20日 星期六
Python C++採Greedy 2 pointers解Leetcode 1605 Find Valid Matrix Given Row ...
Python CPP採Greedy 2pointers解Leetcode 1605 Find Valid Matrix Given Row and Column Sums
將大小為 r*c 的陣列 arr 初始化為全 0
獨立的 i、j 是 2 個指標。使用迴圈繼續
設 x=min(rowSum[i], colSum[j])
設定 arr[i][j]=x & rowSum[i]-=x, colSum[j]-=x 根據 rowSum[i]==0 & colSum[j]==0 移動 i, j。
[Python解請進]
----
按我讀文 »
2024年7月2日 星期二
Python C++速解multiset問題Leetcode 350 Intersection of Two Arrays II
Python C++速解multiset問題Leetcode 350 Intersection of Two Arrays II
兩個多重集合(multiset)的交集是兩個多重集中公共元素的多重集合。
Python code請進
按我讀文 »
2024年6月26日 星期三
Python C++ InOrder與Greedy解Leetcode 1382 Balance a Binary Search Tree
Python C++ InOrder與Greedy解Leetcode 1382 Balance a Binary Search Tree
使用中序/逆中序走訪建立按升序/降序排序的 int 陣列。
貪婪演算法(分而治之)建構平衡的 BST。
Python code請進
按我讀文 »
2024年6月15日 星期六
Python C++ Sort,Priority Queue, Binary search解Leetcode難題502 IPO
Python C++ Sort Priority Queue Binary search解Leetcode難題502 IPO
建立一個容器 cp,裡面包含配對的資訊 (capital[i], profits[i]),其中 i 從 0 到 n-1。
將 cp 按照字典順序(預設排序)進行排序。
(Python code請進)
按我讀文 »
2024年6月14日 星期五
Python C++計數速解Leetcode 945 Minimum Increment to Make Array Unique
Python C++計數速解Leetcode 945 Minimum Increment to Make Array Unique
先計數每個x出現幾次,再從小而大,把多餘的x移動到下一個數字x+1
Python解答請進
按我讀文 »
2024年6月10日 星期一
Python C++計數排序與一行解Leetcode 1051 Height Checker
套用系統排序函數解當然簡單,自己造輪子就稍微進階點,觀察輸入資料限制,counting sort應該是可以自造又不失為簡單且線性時間的解答。
Python C++計數排序與一行解Leetcode 1051 Height Checker
Python 1 行解以及
計數排序的解,它使用計數排序並重複使用heights來存原始陣列和排序後的差異;然後使用 |heights|-count(heights, 0) 給出答案。 C++ 和 python 程式碼都已製作。
一行解請進
按我讀文 »
2024年6月9日 星期日
Python C++ prefix sum mod k陣列和公式解Leetcode 974 Subarray Sums Divisible...
Python C++ prefix sum mod k陣列和公式解Leetcode 974 Subarray Sums Divisible by K
昨天的問題523. Continuous Subarray Sum會解,今日Leetcode 974. Subarray Sums Divisible by K更沒問題,看一下constraints hash map就不用了,馬上就能解答
Python code請進
----------
按我讀文 »
較新的文章
較舊的文章
首頁
訂閱:
文章 (Atom)
熱門文章
計算你上學期加權平均
計算你上學期加權平均
河內塔程式
河內塔程式
「全民資安素養自我評量」
教育部為提昇全民資安素養與電腦防護能力,本部於101年9月5日至11月5日舉辦「全民資安素養自我評量」活動,請在活動期間內踴躍上網檢測資訊安全素養認知程度,並有機會參與抽獎,詳情請參閱活動網站(網址: https://isafe.moe.edu.tw/event
費氏數列
將費氏數列輸出至一long 陣列 其中f[0]=1, f[1]=2, f[n]=f[n-1]+f[n-2] (n>=2)
Fibonacci Sequence(1)
Fibonacci sequence: a[0]=1, a[1]=1, a[2]=2, a[3]=3, a[4]=5,...... In general, a[n]=1 as n=0,1, a[n]=a[n-1]+a[n-2] as n>=2. Use this...
簡答題
簡答題: 比較C/C++, Java, VB的差異!
算上學期加權平均
算上學期加權平均
資料結構統計
LinkedList Exercise mm/dd Java 中的 LinkedList mm/dd 列印課表 mm/dd GCD mm/dd Ex2 mm/dd 用Eclipse寫hello.java mm/dd
Ex8. 費氏數列Visual C#遞迴函式實作 Fibonacci sequence
1. 何謂遞迴函數? 2. 實作費氏數列,用遞迴方法
解一元二次方程式
解一元二次方程式 ax^2+bx+c=0, x=?