title: Leetcode 1588 sum of all ODD length subarrays. C++
body: <p>I'm practicing myself by doing some leetcode questions, however, I don't know why that's an overflow problem right here. I knew the way I sum the subarray was terrible, any tips for the sum of the subarray?
  and the run time for this code would be forever</p>
  <pre><code>#include &lt;numeric&gt;
  class Solution {
  public:
     int sumOddLengthSubarrays(vector&lt;int&gt;&amp; arr) {
         int size = arr.size();//5
         int ans = 0;
         int sumAll = 0;
         int start = 3;
         int tempsum;
         for(int i =0; i&lt; size; i++){ //sumitself
              sumAll += arr[i];
         }
         ans = sumAll; //alreayd have the 1 index
         if(size%2 == 0){//even number 6
             int temp = size-1; //5
             if(size == 2)
                 ans = sumAll;
             else{
                 while(start &lt;= temp){//3 &lt; 5
                     for(int i = 0; i&lt; size; i++){
                         for(int k =0; k&lt; start; k++){//3
                         tempsum += arr[i+k];
                         if(i+k &gt; temp) //reach 5
                          break;
                  }
                 }                  
                 start+=2;
              }
          }
              ans+= tempsum;
          }
              
      else{//odd number 
          if(size == 1)
              ans = sumAll;
          else{
              while(start &lt; size){//3
                  for(int i = 0; i&lt; size; i++){
                     for(int k =0; k&lt; start; k++){//3
                      tempsum += arr[i+k];
                      if(i+k &gt; size) //reach 5
                          break;
                  }  
              }
              start+=2;
          }
          ans+= tempsum;
          ans+= sumAll; //size index
      }
              
      
      
  }
      return ans;
  }
    };
  </code></pre>