你好,我是 Yama,歡迎來到我的網站。
Contact Me
- Email: [email protected]
- GitHub: @9501sam
課程連結:6.S081 Fall 2020 Lecture 21: Networking Protocal nesting header 的 type 決定了之後的內容要如何解讀 The OS network stack tcpdump 的解析 Queue 的使用 影片中有提及不管是在那一個層級的 stack 當中,queue 的使用都是很常見的 可能會有一個 buffer allocator MBUF E1000 NIC 這在 lab: network driver 中會運用的一個 NIC, 影片中有提及跟現代的 NIC 比較起來 現在的 NIC 當中有做一些 check Livelock Problem 最後的結論是用 Polling 來解決
Lab 連結:Lab net: Network driver Background You’ll use a network device called the E1000 to handle network communication. To xv6 (and the driver you write), the E1000 looks like a real piece of hardware connected to a real Ethernet local area network (LAN). In fact, the E1000 your driver will talk to is an emulation provided by qemu, connected to a LAN that is also emulated by qemu. On this emulated LAN, xv6 (the “guest”) has an IP address of 10.0.2.15. Qemu also arranges for the computer running qemu to appear on the LAN with IP address 10.0.2.2. When xv6 uses the E1000 to send a packet to 10.0.2.2, qemu delivers the packet to the appropriate application on the (real) computer on which you’re running qemu (the “host”). ...
題目連結:136. Single Number 解題思路 這題是一個蠻神奇蠻剛好的一題,同時使用了 xor 與「出現兩次」這兩個元素,因為 同一個數字 xor 在一起會變成 0 這題就用這樣的特性解決 程式碼 class Solution { public: int singleNumber(vector<int>& nums) { int n = 0; for (int num : nums) n ^= num; return n; } };
題目連結:746. Min Cost Climbing Stairs 解題思路 這題利用 DP 的方式,「有了前兩天的資訊可以推測出今天」依此類推的得知最後的答案。 程式碼 class Solution { public: int minCostClimbingStairs(vector<int>& cost) { int n = cost.size(); vector<int> dp(n, 0); dp[0] = cost[0]; dp[1] = cost[1]; for (int i = 2; i < n; i++) dp[i] = min(dp[i - 1], dp[i - 2]) + cost[i]; return min(dp[n - 1], dp[n - 2]); } };
題目連結:1004. Max Consecutive Ones III 解題思路 這題使用兩個 pointer left 與 right 來紀錄當前的 array 大小,像是: 0 1 2 3 4 5 6 7 8 9 ↑ ↑ l r 這個時候 left == 2, right == 6 長度的計算為 length = right - left + 1 也就是 6 - 2 + 1 == 5 如何表達 length == 0 這樣的設計會碰到的下一個問題是 假設 right == 6 如何表達 length == 0 的情況?? 會像是下面這個樣子: 0 1 2 3 4 5 6 7 8 9 ↑ ↑ r l 雖然是 left 不過卻在 right 的右邊,但這樣做的好處就在於我們計算長度的公式: ...
題目連結:1679. Max Number of K-Sum Pairs 解題思路 這一題跟 11. Container With Most Water 的感覺還蠻像的,都是先把兩的 pointer 放在兩端,並且根據不同的情況,用 greedy 的方式判斷下一步要做什麼。還有這個問題是配對到了就刪除掉,所以也不會有重複的問題。 程式碼 class Solution { public: int maxOperations(vector<int>& nums, int k) { int left = 0; int right = nums.size() - 1; int count = 0; sort(nums.begin(), nums.end()); while (left < right) { if (nums[left] + nums[right] == k) { count++; left++; right--; } else if (nums[left] + nums[right] < k) { left++; } else { right--; } } return count; } };
題目連結:345. Reverse Vowels of a String 解題思路 這題就很直覺得掃過兩遍,第一遍收集 Vowels,第二變把 Vowels 用相反的順序放回去,真有什麼好說的東西的話應該是寫個 helper function isVowels() 會方便一些。 程式碼 class Solution { private: bool isVowels(char c) { if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') return true; if (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U') return true; return false; } public: string reverseVowels(string s) { int n = s.size(); queue<char> q; for (int i = 0; i < n; i++) if (isVowels(s[i])) q.push(s[i]); for (int i = n - 1; i >= 0; i--) if (isVowels(s[i])) { s[i] = q.front(); q.pop(); } return s; } };
題目連結:334. Increasing Triplet Subsequence 解題思路 這題我剛開始是朝著先找出 i 與 k 之後再檢查 j 是否存在,想了幾遍都覺得有些瑕疵,後來發現依照 i, j, k 的順序尋找會比較合理一些,可以用很 greedy 的方式去尋找。 如果再來一次的話,我應該會先列出以下兩種可能: 先找出最大最小的 i 與 k, 再找出中間的 j 依照順序尋找 i, j, k 評估之後挑選較有可能的順序,並且保持另一個方案的可能性。 程式碼 class Solution { public: bool increasingTriplet(vector<int>& nums) { if (nums.size() < 3) return false; int i = 0; int j = -1; for (int l = 1; l < nums.size(); l++) { if (nums[l] < nums[i]) { i = l; } else if (j > 0 && nums[l] > nums[j]) { return true; } else if (nums[l] > nums[i]) { j = l; } } return false; } };
sudo apt-get update sudo apt-get install -y kubelet kubeadm kubectl sudo apt-mark hold kubelet kubeadm kubectl https://stackoverflow.com/questions/52893111/no-endpoints-available-for-service-kubernetes-dashboard nodes: https://120.108.205.137:9999/ui/ 192.168.1.115 ssh k1 # ssh [email protected] ssh k2 # ssh [email protected] ssh k3 # ssh [email protected] ssh k4 # ssh [email protected] sudo vim /etc/hosts # /etc/hosts 192.168.1.115 asus 192.168.1.11 k1 192.168.1.12 k2 192.168.1.13 k3 192.168.1.14 k4 # for cluster on virtualbox 192.168.56.1 thinkpad # my thinkpad 192.168.56.101 node1 # vm on virtualbox sudo systemctl restart systemd-resolved docker installation https://docs.docker.com/engine/install/ubuntu/ CRI (container runtime interface) 是 container 用來互相溝通的 API ...
This is my first article! 所以我說那個醬汁呢?