Leetcode brush the daily problem and the next problem of the daily problem note 13/30
Writing in the front
This is the 13th 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 to say the first two questions of the thirteenth day!
2021.6.13 One question of the day
278. The first incorrect version
This problem uses binary search, when calculating the middle number, we should pay attention to change the calculation formula to prevent crossing the boundary.
// The API isBadVersion is defined for you.
// bool isBadVersion(int version);
class Solution {
public:
int firstBadVersion(int n) {
int left = 1, right = n;
while (left < right) {
int mid = left + (right - left) / 2;
if (isBadVersion(mid)) {
right = mid;
} else {
left = mid + 1; }}returnleft; }};Copy the code
There was a test case that used the maximum int, which was out of bounds, so the form of the dish was changed.
One of the following questions per day
1137. The NTH Tebonacci number
I think we could solve the characteristic equation and then write out the general formula, and then we could use the formula, but the recursion is the easiest.
class Solution {
public:
int dp[38];
int tribonacci(int n) {
if(! n) dp[n] =0;
else if(n == 1 || n == 2) dp[n] = 1;
else if(! dp[n]) dp[n] =tribonacci(n - 1) + tribonacci(n - 2) + tribonacci(n - 3);
returndp[n]; }};Copy the code
summary
Today’s problem is really easy, holiday.
Refer to the link
There is no