<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: guang</title>
    <description>The latest articles on DEV Community by guang (@guang2025).</description>
    <link>https://dev.to/guang2025</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3096694%2Fa865b076-a24b-4c5f-bc61-a0fe0ba838d7.png</url>
      <title>DEV Community: guang</title>
      <link>https://dev.to/guang2025</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/guang2025"/>
    <language>en</language>
    <item>
      <title>leetcode2 add two numbers</title>
      <dc:creator>guang</dc:creator>
      <pubDate>Tue, 17 Jun 2025 11:41:45 +0000</pubDate>
      <link>https://dev.to/guang2025/leetcode2-add-two-numbers-5fc</link>
      <guid>https://dev.to/guang2025/leetcode2-add-two-numbers-5fc</guid>
      <description>&lt;p&gt;i used two approached, one is with additional stack, another is reusing the linked list of the longer one to reduce the space usage.so i compare the length of them firstly.&lt;br&gt;
in the official solution, they just create new nodes, and link them naturally, it is very clean. while i don't know why i create a dummy head, and another node pointing to dummy head, it makes code complicated, so confusing why i do that.&lt;br&gt;
they only have two condition statement, if l1 exist, add it to summary result, if l2 exist, add to the summary result too. it is so clean. why i have there condition statement, one is both l1 and l2 exist, one is only l1 exist, and else. it's complicated and not that readable.&lt;/p&gt;

</description>
      <category>leetcode</category>
      <category>algorithms</category>
      <category>programming</category>
      <category>refactor</category>
    </item>
    <item>
      <title>leetcode 150 evaluate reverse polish notation</title>
      <dc:creator>guang</dc:creator>
      <pubDate>Tue, 17 Jun 2025 09:00:16 +0000</pubDate>
      <link>https://dev.to/guang2025/leetcode-150-evaluate-reverse-polish-notation-1532</link>
      <guid>https://dev.to/guang2025/leetcode-150-evaluate-reverse-polish-notation-1532</guid>
      <description>&lt;p&gt;at first i was worried since i didn't have any clue at all. i think it's hard to handle from the head of the list, since there's no rule in the numbers and operators. after racked my brain for one hour in the library, i finally get a clue. use stack to help, push them into stack from end of the list, when there is two numbers and a operator in a row, push them out and evaluate them, push the result back. i was so glad i solve it by myself. but it only beat 6% of person in time. i thought my time complexity is squared n, but it shows the time complexity is only n. maybe it's caused by the condition statement to check whether it's a number. in the solution, it used not in "+-*/", it's clean. but i used in "0123456789".&lt;br&gt;
in the solution it also handle from the head of the list, and the core logic is same: when come across, operator, evaluate the operator and the two numbers before it.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>leetcode 155 mini stack</title>
      <dc:creator>guang</dc:creator>
      <pubDate>Sun, 08 Jun 2025 15:24:20 +0000</pubDate>
      <link>https://dev.to/guang2025/leetcode-155-mini-stack-aj9</link>
      <guid>https://dev.to/guang2025/leetcode-155-mini-stack-aj9</guid>
      <description>&lt;p&gt;i am so glad i figure it out by myself. at first i just used a minval to save the min val of the stack, but when the min val is popped, the code went wrong. then i try to use another variable to save the next min val, but if it is also popped, the same problem occurred. then i have to use a stack to save the correspond min val when the item is popped out. at last i use a history min stack to save the history min value when the min value is changed. so it start from the second item, in the solution, they save the min value for every item, then when the item is popped, the min stack also popped, and when get min value, just return the top of min stack, that's more clean.&lt;br&gt;
i also thought about dictionary, save every item and correspond min value, but the remove and pop function of dictionary need key as parameters, so i give up this way, but just now i know in python3, there's also function to pop the last inserted item. and there seems also solution using this way, with one stack.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>leetcode 20 valid parentheses</title>
      <dc:creator>guang</dc:creator>
      <pubDate>Sun, 08 Jun 2025 14:58:18 +0000</pubDate>
      <link>https://dev.to/guang2025/leetcode-20-valid-parentheses-afi</link>
      <guid>https://dev.to/guang2025/leetcode-20-valid-parentheses-afi</guid>
      <description>&lt;p&gt;at first i didn't have any clue about the problem, then i think it's problem about stack, i should resolve it by stack, push the string into stack and when the parentheses match, pop them. i used match of python3 to check if the parentheses match, in the solution they use dictionary, that's quite clean. actually the idea of using dictionary do pass by my brain but i didn't catch it. it's a little complicated and i was eager to verify my solution quickly in an easy way way although it was not clean.&lt;/p&gt;

</description>
      <category>leetcode</category>
      <category>algorithms</category>
      <category>python</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>leetcode 92 reverse linked list II</title>
      <dc:creator>guang</dc:creator>
      <pubDate>Tue, 27 May 2025 14:46:07 +0000</pubDate>
      <link>https://dev.to/guang2025/leetcode-92-reverse-linked-list-ii-32hk</link>
      <guid>https://dev.to/guang2025/leetcode-92-reverse-linked-list-ii-32hk</guid>
      <description>&lt;p&gt;i used two way to solve the problem, one is head insertion, one is as in the problem 206 reverse linked list, just reverse the link between every node. but in my solution, it is also clumsy and complicated. compare with the official solution, i used while to loop, and use a lot of variable, pre-left, reversed-head, reversed-end, while in the official solution, they only used pre, pre.next is always the reversed-head, and they use for to loop, cur always pointer to reversed-end.it's so ingenious.&lt;br&gt;
i also update my code of problem 206 reverse linked list accordingly, remove the temporary variable of reversed-head. it's more clean and neat.&lt;/p&gt;

</description>
      <category>leetcode</category>
      <category>programming</category>
      <category>algorithms</category>
      <category>code</category>
    </item>
    <item>
      <title>leetcode 328 odd even linked list</title>
      <dc:creator>guang</dc:creator>
      <pubDate>Thu, 22 May 2025 10:24:51 +0000</pubDate>
      <link>https://dev.to/guang2025/leetcode-328-odd-even-linked-list-4emh</link>
      <guid>https://dev.to/guang2025/leetcode-328-odd-even-linked-list-4emh</guid>
      <description>&lt;p&gt;at first i want to traverse two times, first to get the odd nodes then even nodes, then combine them together。after i leaved the library, i am thinking about it when my brain get a slot from cooking and walking dog. right before i was going to bed, i got an idea, using two pointer to get odd nodes and even nodes at the same time. i am so glad i can't wait for tomorrow. i am tired but i still begin to code. &lt;/p&gt;

&lt;p&gt;i pointer odd and even to the first two nodes, so i suppose i should start loop from the third and fourth nodes, the code looks kind of weird as&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;event.next = event.next.next&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;and when it comes to the fifth node, it can't meet the loop condition. so i add dummy nodes to loop from the first two nodes, then it said Memory Limit Exceeded, at first i suppose it was caused by the space complexity, i used two nodes, but chatgtp said with two node, the space complexity is still o(1), the root cause is cycle in the linked list after i combine two links.&lt;/p&gt;

&lt;p&gt;at last i choose another clumsy approach, i was so close to the right approach, just need more rounds try.&lt;/p&gt;

&lt;p&gt;actually i really don't need dummy node, since the head doesn't change. it's always the head of odd nodes, the list.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>leetcode 21</title>
      <dc:creator>guang</dc:creator>
      <pubDate>Tue, 20 May 2025 15:18:41 +0000</pubDate>
      <link>https://dev.to/guang2025/leetcode-21-4fod</link>
      <guid>https://dev.to/guang2025/leetcode-21-4fod</guid>
      <description>&lt;p&gt;can't believe i used so clumsy way.i put dummy point to head as usual, then compare first value of list1 and list2, insert list2 node before or after list1 node. i also need consider the next node of list1. i doubt why it's so complicated for an easy problem but i didn't doubt about my solution! i also forgot to save node beforehand when swap node.&lt;br&gt;
in the official solution, it's really simple and clean, didn't put dummy point to any node at first, then put it to smaller one of list1 and list2.&lt;br&gt;
i also learned another recursive way.&lt;br&gt;
i also learned an easy way to assign using or:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;cur = list1 or list2&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>leetcode</category>
      <category>programming</category>
      <category>coding</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>leetcode 160</title>
      <dc:creator>guang</dc:creator>
      <pubDate>Fri, 16 May 2025 14:49:59 +0000</pubDate>
      <link>https://dev.to/guang2025/leetcode-160-14pg</link>
      <guid>https://dev.to/guang2025/leetcode-160-14pg</guid>
      <description>&lt;p&gt;i can't believe it's easy class. it's so hard for me, yesterday afternoon i feel there's no way to solve it except with complexity m*n. today i struggled all day but failed to find a way of complexity m+n. i feel so frustrated then i checked the solution after 15:00. jesus, i should check the solution earlier since i can never thought of switch head when hit the end. what's that? that's out of the common human ability like me.&lt;br&gt;
as for the length difference way, that's also kind of weird for me, cause there's no clue in the problem description the two list intersected till the end, though in all the example they do intersected till the end.&lt;/p&gt;

</description>
      <category>leetcode</category>
      <category>programming</category>
      <category>algorithms</category>
      <category>productivity</category>
    </item>
    <item>
      <title>leetcode 24</title>
      <dc:creator>guang</dc:creator>
      <pubDate>Thu, 15 May 2025 14:39:02 +0000</pubDate>
      <link>https://dev.to/guang2025/leetcode-24-3d41</link>
      <guid>https://dev.to/guang2025/leetcode-24-3d41</guid>
      <description>&lt;p&gt;i used two way to solve the problem. the first way is to consider the situation of third node and forth node, to put the first node point to fourth node.it looks so complicated. in second way, i didn't care about the third and fourth node, just set a pre pointer to update it point to swapped node in next round. it's more clean but still a little bit complicated. i did following things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;preserve the pointer for next round&lt;/li&gt;
&lt;li&gt;handle the case if it's the end of list&lt;/li&gt;
&lt;li&gt;swap&lt;/li&gt;
&lt;li&gt;handle the case if it's head.(i didn't use dummy node)&lt;/li&gt;
&lt;li&gt;hande pre pointer.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;in the solution ,the code is more clean cause they only consider about the case when first and second node both exists, cause if the second one doesn't exist, there's no need to reverse the link. they also put the first node point third node and i only put it pointe to none when it's the last one.someone even swap the three nodes in one line!&lt;/p&gt;

&lt;p&gt;i also learned to initiate dummy node in one line.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>leetcode 19</title>
      <dc:creator>guang</dc:creator>
      <pubDate>Tue, 13 May 2025 13:55:19 +0000</pubDate>
      <link>https://dev.to/guang2025/leetcode-19-1ali</link>
      <guid>https://dev.to/guang2025/leetcode-19-1ali</guid>
      <description>&lt;p&gt;it's hard for me. the annoying chatgpt give me a hint to use two pointer while i didn't asked and wanted when i asked another question. at first i have no clue even with the hint. but yesterday night when i go to bed i thought hardly and finally get the solution before i fell sleep. that's use two pointer to record the distance n between them! but i am not sure if without the annoying hint, can i solve it by myself.&lt;br&gt;
in the solution the move faster pointer n times before move slower pointer. that seems more intuitive than mine: start both of the pointer from dummy head and count n than begin to move slower pointer.&lt;br&gt;
i also learned from the author his way of thinking.&lt;/p&gt;

</description>
      <category>leetcode</category>
      <category>programming</category>
      <category>learning</category>
      <category>chatgpt</category>
    </item>
    <item>
      <title>leetcode 203</title>
      <dc:creator>guang</dc:creator>
      <pubDate>Mon, 12 May 2025 14:46:08 +0000</pubDate>
      <link>https://dev.to/guang2025/leetcode-203-3760</link>
      <guid>https://dev.to/guang2025/leetcode-203-3760</guid>
      <description>&lt;p&gt;the next problem of the problem-solving guide is actually number 24, swap nodes in pairs, that's too hard for me. so i choose 203 to get familiar with single linked nodes first. my first several rounds of submission failed and i updated several times and it finally submitted successfully. today when i checked the solution, i learned from the poster to make a list of edge cases before writing any code, i think that's better than update every time when it fails. it will be more effective and i can also practice writing edge cases beforehand.&lt;br&gt;
my code is not that neat cause i have a conditional statement of iterator node which is actually intermediate code when debug failed edge case. so if i get edge cases beforehand, there won't be such dirty code.&lt;br&gt;
i also updated head node every time when head node value is target value. cause i use dummy node directly as iterator node, in the solution she create a new variable as iterator so the dummy node aways point to head node.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>leetcode 27</title>
      <dc:creator>guang</dc:creator>
      <pubDate>Wed, 07 May 2025 13:25:57 +0000</pubDate>
      <link>https://dev.to/guang2025/leetcode-27-3nk0</link>
      <guid>https://dev.to/guang2025/leetcode-27-3nk0</guid>
      <description>&lt;p&gt;i found it is same with move zero problem, the difference are it's a specific value and the original order of the numbers is not cared. so i use the two pointer just as move zero problem. it works! since the original order is not required i think there maybe better way to solve the problem. i tried begin one pointer backwards, it failed a lot of times, it's horrible, so many edge cases to take care, even though the code was submit successfully but the logic is really in a mess. i gave up to refactor and check the solutions. in the solution they don't exchange the two value, just replace since the order is not required. but in the process of trying to find better way, i learned to take edge cases into account.&lt;br&gt;
when i want to double check the algorithm of move zero, i mistook it's number as 26. after reading the description i found i don't know how to solve it! there's totally no clue in my mind about the solution i once checked. i tried hardly and finally solve it by myself! that's great.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
