avatar
文章
325
標籤
86
分類
15

首頁
文章
標籤
分類
關於
Larry's notes
搜尋
首頁
文章
標籤
分類
關於
LeetCode - 35 解題紀錄
發表於2021-01-02|LeetCode
題目: LeetCode - 35. Search Insert Position 題目說明給一個由小至大排序的陣列,及一個 target,求 target 應該插入到的位置 ( index )。 解題思路由於是排序過的陣列,所以使用二分法查詢即可。 ( 可直接使用 lower_bound() 完成二分法 ) 參考解法12345678910111213141516171819202122class Solution {public: int searchInsert(vector<int>& nums, int target) { return binarySearch(nums, target); //return lower_bound(begin(nums), end(nums), target) - begin(nums); } private: int binarySearch(vector<int>& nums, int target) ...
LeetCode - 24 解題紀錄
發表於2021-01-02|LeetCode
題目: LeetCode - 24. Swap Nodes in Pairs 題目說明給一個 Linked List,將相鄰的兩個 node 互換 ( 1、2 互換,3、4 互換)。最後回傳互換後的 head。 解題思路使用 Recursive 的概念,先將第二個 node 保存,之後呼叫並傳入第三個 node,最後把第一個 node 接到第二個 node 後面即可。 參考解法1234567891011class Solution {public: ListNode* swapPairs(ListNode* head) { if (!head || !head->next) return head; auto tmp = head->next; head->next = swapPairs(head->next->next); tmp->next = head; return tmp; }};
LeetCode - 27 解題紀錄
發表於2021-01-02|LeetCode
題目: LeetCode - 27. Remove Element 題目說明給一個陣列,求刪除某個特定數字後的陣列及其大小。 ※ 題目希望使用原本的陣列來達成,不要建立額外的陣列,也就是空間複雜度為 O(1) 的意思。 解題思路遍歷陣列,若值不等於要刪除的值則從頭開始放入陣列。 參考解法123456789class Solution {public: int removeElement(vector<int>& nums, int val) { int l = 0; for (auto& n : nums) if (n != val) nums[l++] = n; return l; }};
LeetCode - 26 解題紀錄
發表於2021-01-02|LeetCode
題目: LeetCode - 26. Remove Duplicates from Sorted Array 題目說明給一個由小到大排序好的陣列,要求刪除陣列中重複的數字,並回傳處理後的陣列的大小。 ※ 題目希望使用原本的陣列來達成,不要建立額外的陣列,也就是空間複雜度為 O(1) 的意思。 解題思路先判斷 nums 是否為空,若為空直接回傳 0。定義 idx 紀錄目前的 index,由於陣列是排序好的,重複的數字會被排在一起,所以依序遍歷陣列,若碰到與 nums[idx] 不同的數字,則放入 nums[idx + 1],同時將 idx + 1,最後回傳 idx + 1,因為題目要求回傳的是大小。 參考解法12345678910class Solution {public: int removeDuplicates(vector<int>& nums) { if (nums.empty()) return 0; int idx = 0; for (auto& n : nums) i ...
Homework 4 - Distance Measurement
發表於2020-12-30|1091LinearAlgebra-YzuCse
課程名稱:線性代數 CS233 B授課教師:簡廷因發放時間:2020-12-22截止時間:2020-01-19 23:59:59 題目說明本次的作業是影像測距,給一個固定長度的物體,推算其距離。( 利用 data.jpg 算出焦距後套用至所有的測資檢測 ) 本次作業可使用 OpenCV 套件 解題思路照著 HW4.v1.pdf 的說明步驟完成即可。 參考解法123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687#include <iostream>#include <opencv2/opencv.hpp>#include <opencv2/imgproc/types_c.h>using namespace std;using namespace cv;/*reference:f ...
Final Exam
發表於2020-12-20|1091DataStructures-YzuCse
課程名稱:資料結構 CS203 A授課教師:林基成考試時間:2020-12-20 題目說明本次考試為兩題 UVa 的題目,一題為:UVa - 673 - Parentheses Balance,一題選自作業:UVa - 10972 - RevolC FaeLoN。 解題思路 UVa - 673 - Parentheses Balance:UVa - 673 解題紀錄 UVa - 10972 - RevolC FaeLoN:UVa - 10972 解題紀錄 這次考的還算輕鬆,第一題老師放海,第二題是作業中比較有印象的一題,但是考試的時候把兩題同時寫,導致兩題都有點小錯誤,花了不少時間 Debug,希望能記取這次的教訓。。。
UVa - 673 解題紀錄
發表於2020-12-20|UVa
題目: UVa - 673 - Parentheses Balance 題目說明給一個只包含括弧的字串 ('('、')'、'['、']'),成對的相鄰括弧可以相互消除,如: “([()])()” -> “([[]()])()” -> “([()])()” -> “([])()” -> “()()” -> “()“ -> “” 若消除後的字串為空或原本就為空字串則輸出 "Yes",否則輸出 "No"。 解題思路基本的 Stack 觀念,使用 Stack 模擬操作即可。 參考解法12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152#include <iostream>#include <string>#include <stack>using namespace std;sta ...
Homework 3 - FFT
發表於2020-12-11|1091LinearAlgebra-YzuCse
課程名稱:線性代數 CS233 B授課教師:簡廷因發放時間:2020-12-01截止時間:2020-12-22 23:59:59 題目說明給一些訊號,求做完傅立葉轉換後的結果。 解題思路我完全不會,我是抄 這篇 的。 參考解法123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109#include <iostream>#include <iomanip>#include <fstream>#include <vector>#include <string>#include <sstream>#include <cmath>#d ...
Homework 11 - UVa (Dijkstra’s Algorithm, The Bellman-Ford Algorithm)
發表於2020-12-07|1091DataStructures-YzuCse
課程名稱:資料結構 CS203 A授課教師:林基成發放時間:2020-11-30截止時間:2020-12-07 題目說明這次的作業是 UVa 中的 6 題題目。三題與 Dijkstra’s Algorithm 相關,三題與 The Bellman-Ford Algorithm 相關。 與 Dijkstra’s Algorithm 相關 UVa - 929 - Number Maze:UVa - 929 解題紀錄 UVa - 1112 - Mice and Maze:UVa - 1112 解題紀錄 UVa - 10986 - Sending email:UVa - 10986 解題紀錄 與 The Bellman-Ford Algorithm 相關 UVa - 558 - Wormholes:UVa - 558 解題紀錄 UVa - 10449 - Traffic:UVa - 10449 解題紀錄 UVa - 10557 - XYZZY:UVa - 10557 解題紀錄
UVa - 10557 解題紀錄
發表於2020-12-07|UVa
題目: UVa - 10557 - XYZZY 題目說明給一個有向圖,圖上每個點都會有能量值變化量,初始能量值為 100,求是否能從起點 ( 1 號點 ) 走到終點,且過程中能量值不能為 0。 Input: 每組測資第一行為一整數 N,表示有 N 個點,若為 -1 表示結束,後面 N 行依序為每個點的資訊 (1 ~ N),每行至少有兩個整數,第一個整數表示該點的能量值變化量,後面一個整數表示該點連接到幾個其他的點,後面為該點能連接到的點 ( 單向 )。 Output: 若從起點 ( 1 號點 ) 能走到終點則輸出 "winnable",否則輸出 "hopeless"。 解題思路這個解法需要有 Bellman Ford 演算法的概念。 可以將題目轉換為求最大路徑的問題,由於可能會有正環,所以我們需要知道連接在正環的點是否能到達終點,若可以那表示一定能走到終點,因為可以一直在正環走,使能量值無限。 找出圖上能到達終點的點的問題可以轉換成,在反向的圖上,從終點開始走能到達的點。 所以先讀取測資並建圖,同時建一個反向的圖,接著先找出能到達終點的點,之 ...
1…101112…33
avatar
Larry Lai
文章
325
標籤
86
分類
15
Follow Me
最新評論
正在載入中...
分類
  • 1091DataStructures-YzuCse13
  • 1091LinearAlgebra-YzuCse5
  • 1092IntroductionToAlgorithms-YzuCse12
  • Bitwise1
  • C++5
  • Data Mining1
  • Design Pattern2
  • Hexo1
標籤
0-1 Knapsack AI Anaconda Articulation Points BFS Back Tracking Bellman Ford Bitwise Butterfly C++ CPE - 2020/06/09 CPE - 2020/10/20 CPE - 2020/12/22 Coin Change Computational Geometry Convex Hull DFS Data Mining Deep Learning Design Pattern Dijkstra Dinic Divide and Conquer Dynamic Programming Edmonds-Karp FPS Floyd Cycle Detection Algorithm Floyd-Warshall Graham Scan Graph Hexo Index Sort Kadane Kaggle Kruskcal LDS LIS LeetCode LeetCode - Easy LeetCode - Hard
文章
  • 七月 20235
  • 六月 20231
  • 三月 20231
  • 二月 20231
  • 一月 20231
  • 十一月 20223
  • 十月 20222
  • 七月 20225
網站資訊
文章數目 :
325
已運行時間 :
本站總字數 :
118k
最後更新時間 :
User Map
©2020 - 2023 By Larry Lai
本地搜尋