<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>LeetCode on seth-shi</title><link>https://sethix.com/tags/leetcode/</link><description>Recent content in LeetCode on seth-shi</description><generator>Hugo -- gohugo.io</generator><language>en</language><lastBuildDate>Fri, 29 Jan 2021 15:24:18 +0800</lastBuildDate><atom:link href="https://sethix.com/tags/leetcode/index.xml" rel="self" type="application/rss+xml"/><item><title>I Have a Technique Called Quick Sort</title><link>https://sethix.com/posts/2021012915/</link><pubDate>Fri, 29 Jan 2021 15:24:18 +0800</pubDate><guid>https://sethix.com/posts/2021012915/</guid><description>Recently while solving a problem on LeetCode (finding the kth largest number), I needed to sort an array. Realized I only knew basic sorting algorithms like Bubble Sort and Insertion Sort. Then I reviewed Quick Sort through animated examples online, and implemented my own version (code is similar to common implementations): // 1. Select a pivot element (can choose the first element or random element) // 2. Use two pointers starting from both ends, right pointer moves first // 3.</description></item><item><title>Reverse Linked List - Recursive Approach</title><link>https://sethix.com/posts/2019021815/</link><pubDate>Mon, 18 Feb 2019 15:43:12 +0800</pubDate><guid>https://sethix.com/posts/2019021815/</guid><description>Recently encountered a linked list reversal problem on LeetCode:
Reverse a singly linked list. Example: Input: 1-&amp;gt;2-&amp;gt;3-&amp;gt;4-&amp;gt;5-&amp;gt;NULL Output: 5-&amp;gt;4-&amp;gt;3-&amp;gt;2-&amp;gt;1-&amp;gt;NULL Iterative Solution /** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */ struct ListNode* reverseList(struct ListNode* head) { struct ListNode *tmpHead = head, *nextNode; if (NULL == head) { return head; } while (NULL != head-&amp;gt;next) { // Move the next node of current &amp;#39;head&amp;#39; to real head position nextNode = head-&amp;gt;next; head-&amp;gt;next = head-&amp;gt;next-&amp;gt;next; nextNode-&amp;gt;next = tmpHead; tmpHead = nextNode; } return tmpHead; } Recursive Solution /** * Definition for singly-linked list.</description></item></channel></rss>