###### tags: `Weekly Contest` # Weekly Contest 406 ## [3216. Lexicographically Smallest String After a Swap](https://leetcode.com/problems/lexicographically-smallest-string-after-a-swap) (<font color=#00B8A3>Easy</font>) 限制 : <ul> <li>2 <= s.length <= 100</li> <li>s consists only of digits.</li> </ul> ### Solution #### 時間複雜度: $O(n)$ #### 空間複雜度: $O(1)$ 程式碼: ```c++= class Solution { public: string getSmallestString(string s) { for (int i = 0; i < s.size() - 1; i++) { if (s[i] % 2 == s[i + 1] % 2 && s[i] > s[i + 1]) { swap(s[i], s[i + 1]); break; } } return s; } }; ``` ## [3217. Delete Nodes From Linked List Present in Array](https://leetcode.com/problems/delete-nodes-from-linked-list-present-in-array) (<font color=#FFC011>Medium</font>) 限制 : <ul> <li><code>1 <= nums.length <= 10<sup>5</sup></code></li> <li><code>1 <= nums[i] <= 10<sup>5</sup></code></li> <li><code>All elements in nums are unique.</code></li> <li><code>The number of nodes in the given list is in the range [1, 10<sup>5</sup>].</code></li> <li><code>1 <= Node.val <=10<sup>5</sup></code></li> <li><code>The input is generated such that there is at least one node in the linked list that has a value not present in nums.</code></li> </ul> ### Solution #### 時間複雜度: $O()$ #### 空間複雜度: $O()$ 程式碼: ```c++= class Solution { public: ListNode* modifiedList(vector<int>& nums, ListNode* head) { unordered_set<int> numss(nums.begin(), nums.end()); while (numss.find(head-> val) != numss.end()) { head = head->next; } ListNode* left = head; while (left && left->next != nullptr) { ListNode* right = left->next; while (right && numss.find(right->val) != numss.end()) { left->next = right->next; right = right->next; } left = right; } return head; } }; ``` ## [3]()(<font color=#FFC011>Medium</font>) 限制 : <ul> <li><code>10<sup>4</sup></code></li> </ul> ### Solution #### 時間複雜度: $O()$ #### 空間複雜度: $O()$ 程式碼: ```c++= ``` ## [4]()(<font color=#FF375F>Hard</font>) 限制 : <ul> <li><code>10<sup>4</sup></code></li> </ul> ### Solution #### 時間複雜度: $O()$ #### 空間複雜度: $O()$ 程式碼: ```c++= ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up