Low-level Advanced -200,404 miscellaneous section

leetcode a daily problem

Today is my deduction in force do question the next day, the first time to do a daily question, you write quite violent. Because so far, I have been "the solution can come out and everything will be fine" attitude, the idea did not plan to start knocking code execution several times changed several times. If there was chaos wrote some two days I do not know what the hell to write.

After the solution is difficult to find this question difficult subject, a little happy ( _ ). But I do not understand is how the force buckle assessment difficult.

Topic is this:

  1. Rainwater

Given n each represents a non-negative integer of 1 column width height map calculated Click column arrangement, then able to take much rain rain.

img

The above is an array [0,1,0,2,1,0,1,3,2,1,2,1] FIG highly represented, in this case, can take six units rainwater (blue portion represents the rain). Thank Marcos contribution to this figure.

Example:

Input: [0,1,0,2,1,0,1,3,2,1,2,1]
Output: 6

Source: stay button (LeetCode)
link: https://leetcode-cn.com/problems/trapping-rain-water
copyrighted by deduction from all networks. Commercial reprint please contact the authorized official, non-commercial reprint please indicate the source.

I started the practice:

class Solution {
public:
    int trap(vector<int>& height) {
      int q=0;
      int sum=0;
      for(int i=1;i<height.size();i++){
        if(height[i]>height[i-1]){
            for(int j=i-1;j>q;j--){
                int t=min(height[i],height[q])-height[j];
                if(t>0){
                    sum+=t;height[j]=min(height[i],height[q]);
                }
              }
            
          }
        if(height[i]>=height[q]){
            q=i;
        }
      } 
      return sum;
    }
};

My thinking is: only the left column height increased + need to consider when filled with rain pillars protrude issues, in order to avoid duplication in a place filled with rainwater, each height corresponding space after filling rainwater to be changed, rainwater storage highly regarded as the height of the column.

I see the solution to a problem before we decided to try to improve their own run time. Imagined in the brain, there are two index barabara ...... results exceeded the time limit. Well, I still look at someone else's solution to a problem of it.

See the official stack solution, it suddenly does not react, this is a stack thing! / (¨Ò ¨Ò o) / ~~

Official index also gives a two answer time complexity of O (n), the spatial complexity is O (1) is.

https://leetcode-cn.com/problems/trapping-rain-water/solution/jie-yu-shui-by-leetcode/

A maximum height of the dividing line to the solution also Terrific ah.

First determine the highest pillar, this pillar of the left column there is a right of the highest relied upon, as long as the next highest relied upon while looking for that time when the column to the left from left to right traverse while recording level (up to that time relied upon the left - that time traverse to the column height) on the line. On the right, too.

Page dimmed method

Today is a special day.

No one saw the public the text: https://mp.weixin.qq.com/s/_DA0Lm6nDrLtw6YRpjCWPA

html {
    -webkit-filter: grayscale(100%);
    -moz-filter: grayscale(100%);
    -ms-filter: grayscale(100%);
    -o-filter: grayscale(100%);
    filter: grayscale(100%);
    filter: progid:DXImageTransform.Microsoft.BasicImage(grayscale=1);
}

filterCSS properties will blur or color shift effect is applied to other graphic elements. Filter is typically used to adjust the rendered image, background and border.

Book learning algorithm

Today saw the beginning of "Challenge Programming Contest" mini version (less than one hundred), and received two important information.

The first is a matter of time complexity. Although I know that problem-solving to consider the complexity of the algorithm optimization, but do not know the complexity of what constitutes too high in the competition. The book made a list.

The other is the book with the title and code demonstrates how to reduce complexity, very good example. The title is drawn four cards, digital drawn cards represent adds up to an equal number.

Remember a few functions

max_element (arr [], arr [] + size) for which the container maximum value min_element (arr [], arr [] + size)

binary_search (arr [], arr [] + size, indx) binary search

lower_search (arr [], arr [ ] + size, indx) finds the first is greater than or equal to an element of the Location index value is not returned to return the next element in the last position (out of range)

upper_search (arr [], arr [] + size, indx) finds the first element greater than a certain position

Guess you like

Origin www.cnblogs.com/leefree/p/12634858.html