/images/avatar.png

Patrick Wezhi Xu

LeetCode Weekly Contest 156 and others

Second week of LeetCode Challenge. Participated the virtual contest. Weekly Contest 156 1207. Unique Number of Occurrences https://leetcode.com/contest/weekly-contest-156/problems/unique-number-of-occurrences/ Brute force. Record total occurrence of each number and iterate over it to see if there is any duplication. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 class Solution { public: bool uniqueOccurrences(vector<int>& arr) { unordered_map<int, int> occ; unordered_map<int, bool> flag; for (int i = 0; i < arr.

LeetCode Weekly Contest 155 and others

This is the first week of LeetCode Challenges. It includes weekly contest 155 and other problems. Weekly Contest 155 https://leetcode.com/contest/weekly-contest-155 1200. Minimum Absolute Difference https://leetcode.com/contest/weekly-contest-155/problems/minimum-absolute-difference/ Brute force. Find the minimum absolute difference and then iterate the list again to output the pairs with minimum absolute difference. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 class Solution { public: vector<vector<int>> minimumAbsDifference(vector<int>& arr) { vector<vector<int>> ans; if (arr.

CLDictP: A Command-Line Dictionary Tool

A command line dictionary written in Perl using Merriam-Webster APIs. This is my first project using Perl. I feel it is tedious to type formatted definitions to Quizlet(A website which can make flashcards for you) and I’m too lazy to open browser and online dictionary pages. Why not combining these two? It uses following APIs: Merriam-Webster Learner Merriam-Webster Collegiate For each entry, it contains: Pronunciation: IPA(International Phonetic Alphabet) Part of Speech

Static Linked List - Another Way To Represent Graphs

Static Linked List is a data structure that stores linked list in static arrays. It is usually used to represent graphs. It is very interesting that its Chinese name literally translated as “Linked Forward Star”. You have two choices of paths to understand this. Start from Forward Star. Start from Adjacency List. However, I would recommend to explore both ideas to have a better understanding. If you know some of it or you just don’t care, you can jump to here straight away.

POJ 3279 Fliptile

There are \(M \times N\) \((1 \le M, N \le 15)\)square tiles. Each tile can be flipped and the color of tile can change between black(1) and white(0). When you flip a tile, 4 adjacent tiles will also be flipped. Note that the four adjacent flipped tiles will NOT cause their adjacent tiles to flip. Given a configuration, find the minimum number of flips so that all square tiles become white.