<?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>Forem: hallowaw</title>
    <description>The latest articles on Forem by hallowaw (@hallowaw).</description>
    <link>https://forem.com/hallowaw</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%2F1324342%2Fcdc329de-6707-41b1-b43e-bd50e4a108ef.png</url>
      <title>Forem: hallowaw</title>
      <link>https://forem.com/hallowaw</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/hallowaw"/>
    <language>en</language>
    <item>
      <title>A solution for leetcode problem 20 "valid parentheses"</title>
      <dc:creator>hallowaw</dc:creator>
      <pubDate>Mon, 15 Jul 2024 10:25:03 +0000</pubDate>
      <link>https://forem.com/hallowaw/a-solution-for-leetcode-problem-20-valid-parentheses-3k3d</link>
      <guid>https://forem.com/hallowaw/a-solution-for-leetcode-problem-20-valid-parentheses-3k3d</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fesb2dpy58jc08ojgzqpf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fesb2dpy58jc08ojgzqpf.png" alt="Image description" width="800" height="848"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First we need find out what is the correct corresponding relationship for parentheses?&lt;/strong&gt;&lt;br&gt;
it is not "}" must follow  "{" very closely,and we allow that situation that "{[()]}" and "{&lt;a href=""&gt;&lt;/a&gt;}" even "{[]}()"&lt;/p&gt;

&lt;p&gt;And the true rule we need follow is that each ending parentheses like "),},]"need fit to the last beginning parentheses so that we have the following codes with very detailed explainations:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Solution {
public://the requirement of the problem is to check if the parentheses is conformed by the rules and 
//the rule is that the ending parenthese must correspond to the last beginning parentheses 
    bool isValid(string s) {
        vector&amp;lt;char&amp;gt; vec1;//define a vector 
        bool result=false;//the defualt result it false 
        if(s.length()%2==1){
            return false;
        }//if the length of s is odd,then it can not have the same number of beginning parenthese and ending parenthese
        for (int i = 0; i &amp;lt; s.length(); i = i + 1) 
        {
            char c = s[i];//we let each element in s euqate c,
            if (c == '(' || c == '{' || c == '[') {
                vec1.push_back(c);//and if c equate the beginning parentheses we sotre it in vec1
            }
            else{
                if(vec1.empty())
                {return false;//if c do not equate beginning psrentheses and c is NULL return false 
                }
                else if(c == ')' || c == '}' || c == ']') {
                    //if c equate ending psrentheses 
                    int num=vec1.size()-1;//to make vec[num]is the last element of the vec1
                    if((vec1[num]=='{'&amp;amp;&amp;amp;s[i]=='}')||(vec1[num]=='['&amp;amp;&amp;amp;s[i]==']')||(vec1[num]=='('&amp;amp;&amp;amp;s[i]==')')){
                result=true;
                vec1.pop_back();//if the c is ending parentheses and have the corresponding relationship with the last begining parenthese ,we let result equate true and delete the last beginning parenthese from the vec1
                }
                else{
                    return false;
                }
                }
            }



        }

        if(vec1.empty()){
            return result;
            //if when we finish such operations and there is not elements in the vec1 and each begining parentheses and ending parentheses have correct relation in correct order then output the "true " result.
        }
        else{
            return false;//,maybe there are some elements remain in vec1 so must return false
        }
    }
};





&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>One simple solution for leetcode problem 14</title>
      <dc:creator>hallowaw</dc:creator>
      <pubDate>Mon, 24 Jun 2024 14:42:52 +0000</pubDate>
      <link>https://forem.com/hallowaw/one-simple-solution-for-leetcode-problem-14-32c</link>
      <guid>https://forem.com/hallowaw/one-simple-solution-for-leetcode-problem-14-32c</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fldg26qta0vow53i4ilv1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fldg26qta0vow53i4ilv1.png" alt="Image description" width="800" height="740"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First let us figure out  what should i do,we need find the common prefix for all strings in the vector&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So we just need compare the char in the same position for each string&lt;br&gt;
But how to denote the particular char in the particular string in a vector?&lt;br&gt;
Let us use the example 1 for a explanation&lt;br&gt;
So if we wanna denote the 'r' in the 'flower' ,we can use strs[0][5] to refer 'r'&lt;br&gt;
So now we get the methods to make a comparison for each char,if it is the same we save it into the result string &lt;br&gt;
but we also need to notice if it exit in the position of a string&lt;br&gt;
We use the code to check :if(strs[j][i]=='\0')&lt;/p&gt;

&lt;p&gt;so the full code is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Solution {
public:
    string longestCommonPrefix(vector&amp;lt;string&amp;gt;&amp;amp; strs) {
        //first we define a string for storing the result
        string commonprefix="";
        int condition=1;
        for(int i=0;i&amp;lt;strs[0].size();i++){
            char currentchar=strs[0][i];

            for(int j=1;j&amp;lt;strs.size();j++)
            {
                //should require two conditions :the position of the string is not NULL and same with currentchar,here we use the contrary condition for understand easily.
                if(strs[j][i]=='\0'||strs[j][i]!=currentchar){
                    return commonprefix;
                }
            }
            commonprefix.push_back(currentchar);
        }
        return commonprefix;
    }
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thank you for reading!&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>programming</category>
      <category>tutorial</category>
      <category>cpp</category>
    </item>
    <item>
      <title>the detailed process for sloving leetcode problem 13</title>
      <dc:creator>hallowaw</dc:creator>
      <pubDate>Sat, 15 Jun 2024 13:52:57 +0000</pubDate>
      <link>https://forem.com/hallowaw/the-detailed-process-for-sloving-leetcode-problem-13-3b6k</link>
      <guid>https://forem.com/hallowaw/the-detailed-process-for-sloving-leetcode-problem-13-3b6k</guid>
      <description>&lt;p&gt;&lt;strong&gt;Frist let us see the problem&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzjt99s09c89h5s2yfp8p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzjt99s09c89h5s2yfp8p.png" alt="Image description" width="800" height="861"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To solve the question we need find the rule to calculate the sum of those roman numbers.&lt;/p&gt;

&lt;p&gt;Let us use the LVIII as our first example,we can see that all the roman number left is not smaller than its right,so that we can add the referring integer from right to left,it is 1+1+1+5+50=58,&lt;/p&gt;

&lt;p&gt;And there is another situation,let us use MCMXCIV as our second example,we can find I is behind V,so we should use V subtract I to 5-1=4,and next C is bigger than I so we add C 5-1+100=104,but X is smaller than C so we  subtract X 5-1+100-10=94,then 94+1000-100+1000=1994,&lt;strong&gt;now,we have knew how to calculate the sum of one roman number,start from right and if the left is smaller than right then use right to subtract left else add the left.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;But before this we need to do sth. to let each roman equal a integer to achieve it it is recommend to transfer the form of string to vector that including the integer by the sequence for each roman number so that we are easy to calculate the sum and compare which is bigger for two roman numbers.&lt;br&gt;
so we have the code as following to transfer to integer vector:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;       for(char ch :s){
                switch(ch){
                case 'I':
                newvec.push_back(1);
                break;
                case 'V':
                newvec.push_back(5);
                break;
                case 'X':
                newvec.push_back(10);
                break;
                case 'L':
                newvec.push_back(50);
                break;
                case 'C':
                newvec.push_back(100);
                break;
                case 'D':
                newvec.push_back(500);
                break;
                case 'M':
                newvec.push_back(1000);
                break;

            }

            }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we add the calculating model as following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int size=newvec.size();
        int sum=newvec[size-1];
        for(int i=2;i&amp;lt;=size;i++){
            if (newvec[size-i]&amp;lt;newvec[size-i+1])
            {
            sum=sum-newvec[size-i];
            }
            else{
                sum=sum+newvec[size-i];
            }

        }

        return sum;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;so the full codes is :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Solution {
public:
    int romanToInt(string s) {
         vector&amp;lt;int&amp;gt;vec;

         vector&amp;lt;int&amp;gt;newvec;
            for(char ch :s){
                switch(ch){
                case 'I':
                newvec.push_back(1);
                break;
                case 'V':
                newvec.push_back(5);
                break;
                case 'X':
                newvec.push_back(10);
                break;
                case 'L':
                newvec.push_back(50);
                break;
                case 'C':
                newvec.push_back(100);
                break;
                case 'D':
                newvec.push_back(500);
                break;
                case 'M':
                newvec.push_back(1000);
                break;

            }

            }



        int size=newvec.size();
        int sum=newvec[size-1];
        for(int i=2;i&amp;lt;=size;i++){
            if (newvec[size-i]&amp;lt;newvec[size-i+1])
            {
            sum=sum-newvec[size-i];
            }
            else{
                sum=sum+newvec[size-i];
            }

        }

        return sum;

    }
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>beginners</category>
      <category>programming</category>
      <category>tutorial</category>
      <category>cpp</category>
    </item>
    <item>
      <title>My idea and submission for problem 9 on Leetcode(very detailed)</title>
      <dc:creator>hallowaw</dc:creator>
      <pubDate>Mon, 10 Jun 2024 05:18:01 +0000</pubDate>
      <link>https://forem.com/hallowaw/my-idea-and-submission-for-problem-9-on-leetcodevery-detailed-55d0</link>
      <guid>https://forem.com/hallowaw/my-idea-and-submission-for-problem-9-on-leetcodevery-detailed-55d0</guid>
      <description>&lt;p&gt;The photo of the problem&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foumske2p6vuqzwg2itmv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foumske2p6vuqzwg2itmv.png" alt="Image description" width="800" height="251"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  1. the analysis of the problem:
&lt;/h2&gt;

&lt;p&gt;First we can easily know if the number smaller than 0,it can not be the palindrome number.&lt;br&gt;
We can not compare with the first digit with the last digit,so we need come up with a method to transfer the form so that we can compare easily,then if we transfer the number to an array or vector sucessfully,we can compare the beginning digits with the ending digits easily,&lt;br&gt;
&lt;strong&gt;but before this, we need divide it into two situations:&lt;/strong&gt;&lt;br&gt;
the number of the digit of the number is the odd or even.&lt;br&gt;
we assume size=the number of the digit(same as the length of vector),&lt;/p&gt;

&lt;p&gt;and then &lt;br&gt;
&lt;strong&gt;if the size is odd:&lt;/strong&gt;&lt;br&gt;
we compare the vec[0]with vec[size-1],vec[1]with vec[size-2]......vec[(size-1)/2]with vec[(size+3)/2],leave size[n+1] alone.&lt;br&gt;
if all comparisions equate so the number is palindrome number.&lt;br&gt;
so we have codes as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if(size%2!=0){
            int mid=(size+1)/2;
            for (int i=0;i&amp;lt;mid;i++){
                if (vec[i]!=vec[size-1-i]){
                    return false;
                }
            }
            return true;
        }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;if the size is even:&lt;/strong&gt;&lt;br&gt;
we campare the vec[0]with vec[size-1],vec[1]with vec[size-2]......vec[size/2]withvec[(size/2)+1],if all comparisions equate so the number is palindrome number.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int mid=size/2;
        for (int i=0;i&amp;lt;=mid;i++){
            if(vec[i]!=vec[size-1-i]){
                return false;
            }
        }
        return true;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;so totally we have the complete codes as:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Solution {
public:
    bool isPalindrome(int x) {
        if (x&amp;lt;0){
            return false;
        }//the situation of minus

        string str=to_string(x);
        vector&amp;lt;int&amp;gt;vec;
        for(char digit :str){
        vec.push_back(digit-'0');
        }
        int size=vec.size();
        if(size==1){
            return true ;
        }//the situation of one-digit

        if(size%2!=0){
            int mid=(size+1)/2;
            for (int i=0;i&amp;lt;mid;i++){
                if (vec[i]!=vec[size-1-i]){
                    return false;
                }
            }
            return true;
        }//the situation of odd

        int mid=size/2;
        for (int i=0;i&amp;lt;=mid;i++){
            if(vec[i]!=vec[size-1-i]){
                return false;
            }
        }
        return true;

        //the situation of even

    }
};



//fist discuss the situation od minus,if the number smaller tham 0,then it can not be a palindrome

//we use the function 'string str= to_string(x)' to change the form of x from int to string

//then define a vector 'vecctor&amp;lt;int&amp;gt;vec;

//then we need get each char digit from str

//by using 'result.push_back(digit-'0')' we can get a vector full of integers.

//if there is only one element in the vector ,then it should fit the requirement and is a palindrome.

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>cpp</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>My idea and submission for problem 1 on Leetcode(very detailed)</title>
      <dc:creator>hallowaw</dc:creator>
      <pubDate>Sun, 09 Jun 2024 22:06:35 +0000</pubDate>
      <link>https://forem.com/hallowaw/my-idea-and-submission-for-problem-1-on-leetcodevery-detailed-4p57</link>
      <guid>https://forem.com/hallowaw/my-idea-and-submission-for-problem-1-on-leetcodevery-detailed-4p57</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;1. the analysis of the problem&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fog2dawt6ux325grzn2ut.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fog2dawt6ux325grzn2ut.png" alt="Image description" width="766" height="562"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now we get some information from the question:&lt;/strong&gt;&lt;br&gt;
A array named nums,it includeds some intergers；&lt;br&gt;
An integer named target；&lt;br&gt;
What should we do:we need add two numbers from the nums to make it euqates target then return the indices(or indexs)of the two numbers；&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;example&lt;/strong&gt;:Input: nums = [2,7,11,15], target = 9&lt;br&gt;
Output: [0,1]&lt;br&gt;
when the array nums=[2,7,11,15],we found that only 2+7=9,so we need return the indices of "2" and "7",which is 0 and 1,so the output is [0,1]&lt;br&gt;
&lt;strong&gt;Precondition&lt;/strong&gt;:only one solution in the array given to us,so it won't happen the situation like nums=[1,2,3,4],target=5,because the answer can be 1+4 or 2+3,so it won't happen.and we also can not use the same number for twice,&lt;br&gt;
like in the example:&lt;br&gt;
Input: nums = [3,3], target = 6&lt;br&gt;
Output: [0,1]&lt;br&gt;
we can not use the first "3" twice so we can not get the answer[0,0]&lt;/p&gt;
&lt;h2&gt;
  
  
  2.the method to find the two number
&lt;/h2&gt;

&lt;p&gt;I guess most of us will consider about calculating all possibilities &lt;/p&gt;

&lt;p&gt;so let us use the example of nums = [2,7,11,15], target = 9, at first we need add 2+7,then 2+11,2+15,7+11,7+15,11+15,and check the sum whether equate the target 9,once we find the equal relationship we can end the calculation cause there is only one solution exactly,&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;so how we can do this by codes?&lt;/strong&gt;&lt;br&gt;
 we can start with the nums[0]&lt;br&gt;&lt;br&gt;
0 is the indice of the array,and it start from 0 in any array,it symbols the number in the position of "0+1",in the array nums it is 2&lt;/p&gt;

&lt;p&gt;and then we add the nums[0] with nums[1],it represent 2+7,&lt;br&gt;
then add the nums[0] with nums[2],it represent 2+11,then nums[0]+nums[3] ,nums[1]+nums[2],nums[1]+nums[3] ,nums[2]+nums[3] &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;so we can find the rules:&lt;/strong&gt;&lt;br&gt;
1.fisrt number start from nums[0] to nums[length -2].(we define the lenghth is the quantity of the numbers in the array)&lt;br&gt;
2.the indice of second number is always 1 greater than first number.&lt;/p&gt;

&lt;p&gt;so we have key codes as;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        int n=nums.size();//define n as the length of array nums[]
        for(int i=0;i&amp;lt;n-1;i++){
            for(int j=i+1;j&amp;lt;n;j++){
                if(nums[i]+nums[j]==target){
                    return {i,j};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;then we add this to the given code to spell into a complete code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Solution {
public:
    vector&amp;lt;int&amp;gt; twoSum(vector&amp;lt;int&amp;gt;&amp;amp; nums, int target) {
        //num is the array which we need find two elements to get the right answer.vector is the similar form of array,we can ignore the difference right now.
        //first we make a integer
        int n=nums.size();
        for(int i=0;i&amp;lt;n-1;i++){
            for(int j=i+1;j&amp;lt;n;j++){
                if(nums[i]+nums[j]==target){
                    return {i,j};
                }
            }
        }
        return {};//no solution found
    }
};

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>beginners</category>
      <category>cpp</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
