<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Pytorch on Rui's Blog</title><link>https://low-hands.github.io/posts/algorithm/</link><description>Recent content in Pytorch on Rui's Blog</description><generator>Hugo -- gohugo.io</generator><language>en</language><lastBuildDate>Mon, 19 Jan 2026 23:12:00 -0800</lastBuildDate><atom:link href="https://low-hands.github.io/posts/algorithm/index.xml" rel="self" type="application/rss+xml"/><item><title>Leetcode 541 - Reverse String II</title><link>https://low-hands.github.io/posts/algorithm/twopointers/leetcode-541-%E5%8F%8D%E8%BD%AC%E5%AD%97%E7%AC%A6%E4%B8%B2ii/</link><pubDate>Mon, 19 Jan 2026 23:12:00 -0800</pubDate><guid>https://low-hands.github.io/posts/algorithm/twopointers/leetcode-541-%E5%8F%8D%E8%BD%AC%E5%AD%97%E7%AC%A6%E4%B8%B2ii/</guid><description>&lt;h1 id="leetcode-541-reverse-string-ii"&gt;Leetcode 541. Reverse String II&lt;/h1&gt;
&lt;p&gt;&lt;a href="https://leetcode.cn/problems/reverse-string-ii/description/" target="_blank" rel="noopener"&gt;Problem Link&lt;/a&gt;&lt;/p&gt;
&lt;h2 id="problem-description"&gt;Problem Description&lt;/h2&gt;
&lt;p&gt;Given a string &lt;code&gt;s&lt;/code&gt; and an integer &lt;code&gt;k&lt;/code&gt;, reverse the first &lt;code&gt;k&lt;/code&gt; characters for every &lt;code&gt;2k&lt;/code&gt; characters counting from the start of the string.&lt;/p&gt;
&lt;p&gt;If there are fewer than &lt;code&gt;k&lt;/code&gt; characters left, reverse all of them.&lt;/p&gt;
&lt;p&gt;If there are less than &lt;code&gt;2k&lt;/code&gt; but greater than or equal to &lt;code&gt;k&lt;/code&gt; characters, reverse the first &lt;code&gt;k&lt;/code&gt; characters and leave the other as original.&lt;/p&gt;</description></item><item><title>Leetcode 344 - Reverse String</title><link>https://low-hands.github.io/posts/algorithm/twopointers/leetcode-344-%E5%8F%8D%E8%BD%AC%E5%AD%97%E7%AC%A6%E4%B8%B2/</link><pubDate>Mon, 19 Jan 2026 09:00:00 -0800</pubDate><guid>https://low-hands.github.io/posts/algorithm/twopointers/leetcode-344-%E5%8F%8D%E8%BD%AC%E5%AD%97%E7%AC%A6%E4%B8%B2/</guid><description>&lt;p&gt;&lt;a href="https://leetcode.com/problems/reverse-string/" target="_blank" rel="noopener"&gt;Problem Link&lt;/a&gt;&lt;/p&gt;
&lt;h1 id="problem-description"&gt;Problem Description&lt;/h1&gt;
&lt;p&gt;Write a function that reverses a string. The input string is given as an array of characters s.&lt;/p&gt;
&lt;p&gt;You must do this by modifying the input array in-place with O(1) extra memory.&lt;/p&gt;
&lt;p&gt;Example 1:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Input: s = [&amp;ldquo;h&amp;rdquo;,&amp;ldquo;e&amp;rdquo;,&amp;ldquo;l&amp;rdquo;,&amp;ldquo;l&amp;rdquo;,&amp;ldquo;o&amp;rdquo;]
Output: [&amp;ldquo;o&amp;rdquo;,&amp;ldquo;l&amp;rdquo;,&amp;ldquo;l&amp;rdquo;,&amp;ldquo;e&amp;rdquo;,&amp;ldquo;h&amp;rdquo;]
Example 2:&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;Input: s = [&amp;ldquo;H&amp;rdquo;,&amp;ldquo;a&amp;rdquo;,&amp;ldquo;n&amp;rdquo;,&amp;ldquo;n&amp;rdquo;,&amp;ldquo;a&amp;rdquo;,&amp;ldquo;h&amp;rdquo;]
Output: [&amp;ldquo;h&amp;rdquo;,&amp;ldquo;a&amp;rdquo;,&amp;ldquo;n&amp;rdquo;,&amp;ldquo;n&amp;rdquo;,&amp;ldquo;a&amp;rdquo;,&amp;ldquo;H&amp;rdquo;]&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id="approach"&gt;Approach&lt;/h2&gt;
&lt;p&gt;Opposite Direction Pointers: One pointer starts at the beginning, and the other starts at the end.&lt;/p&gt;
&lt;p&gt;Both pointers move inward simultaneously with the same step size until they cross each other (left &amp;gt; right), at which point the traversal ends.&lt;/p&gt;</description></item><item><title>Leetcode 27 - Remove Element</title><link>https://low-hands.github.io/posts/algorithm/twopointers/leetcode-27-%E7%A7%BB%E9%99%A4%E5%85%83%E7%B4%A0/</link><pubDate>Sun, 18 Jan 2026 22:21:00 -0800</pubDate><guid>https://low-hands.github.io/posts/algorithm/twopointers/leetcode-27-%E7%A7%BB%E9%99%A4%E5%85%83%E7%B4%A0/</guid><description>&lt;p&gt;&lt;a href="https://leetcode.cn/problems/remove-element/description/" target="_blank" rel="noopener"&gt;Problem Link&lt;/a&gt;&lt;/p&gt;
&lt;h2 id="problem-description"&gt;Problem Description&lt;/h2&gt;
&lt;p&gt;Given an array &lt;code&gt;nums&lt;/code&gt; and a value &lt;code&gt;val&lt;/code&gt;, you need to &lt;strong&gt;in-place&lt;/strong&gt; remove all instances of that value and return the new length of the array.&lt;/p&gt;
&lt;p&gt;Do not use extra space for another array; you must do this by modifying the input array &lt;strong&gt;in-place&lt;/strong&gt; with &lt;strong&gt;O(1)&lt;/strong&gt; extra space.&lt;/p&gt;
&lt;p&gt;The order of elements can be changed. You do not need to consider the elements beyond the new length.&lt;/p&gt;</description></item></channel></rss>