Leetcode one problem of the day and the next problem of the day brush problem notes 29/30

Writing in the front

This is the 29th day of my participation in Gwen Challenge

About to graduate, only to find himself in the interview algorithm hanging hammer. There is no way to zero based identity and classmates to join the force buckle brush problem army. My classmates are very good, they are usually just modest, verbally said that they will not, and I really will not… Nuggets encourage new people to blog every day, I also join in a lively, record every day brush the first two questions, these two questions I do. I plan to brush five questions every day. For the other questions, I can only memorize the routine by force and will not post them in my blog.

I am really just a vegetable chicken, what do not want to solve the problem from my reference, coding habits also need to improve, if you want to find brush problem master ask questions, I think it is better to go to the palace water sanye brush problem diary this big guy. I try not to see the solution of the problem before I make it, so as not to collide with the content of the big guy.

In addition, I also hope to have the leisure of the big guy to provide some higher clear problem-solving ideas to me, welcome to discuss ha!

Good nonsense not much say to begin the first two questions of 29 days!

2021.6.29 One question of the day

168. Excel table column name

This is actually a base conversion, so every time you take the remainder you subtract it by one (starting at 0), and then you start at 0 and end at 25 (which is the same thing as starting at 1 and ending at 26). Think of it this way: The numbers of Excel tables are not the numbers that programmers think they are, they’re all the numbers that programmers think they are, and then the last step is converted to non-programmer thinking.

The code is not pasted, and the solution is very similar.

One of the following questions per day

973. K points nearest the origin

You can just take the square of the distance, take the square of the distance, take the time. Using a dichotomy, LET me see if I have the KTH smallest to the left of the point I’m looking for, and if I do, keep looking to the left. If it’s the KTH smallest number, stop, if it’s not, keep looking to the right.


class Solution {
public:
    vector<vector<int>> kClosest(vector<vector<int>>& points, int k) {
        nth_element(points.begin(), 
                    points.begin() + k - 1, 
                    points.end(), [] (const vector<int>& u, const vector<int>& v) {
            return u[0] * u[0] + u[1] * u[1] < v[0] * v[0] + v[1] * v[1];
        });
        return {points.begin(), points.begin() + k}; }};Copy the code

summary

We take the remainder from 0 and number it from 1.

The dichotomy idea is to find the KTH smallest distance

Refer to the link

There is no