Skip to content

quq99/Leetcode_notes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

95 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Leetcode_notes

This is a repo for recording my experience in leetcode.com.

I practice by following the tag in leetcode. In each problem directory, the code can be seen in .cpp file and the notes can be seen in markdown file Solution.md . Enjoy!

What is new in this repo

For each problem in this repo, I write a Solution.md file to record the my thinking process of dealing with the problem, I record how I think about the problem and how I get the optimal solution step by step, from brute force to optimal. Because I think the key point is the way of solving the problem rather than just understand the solution itself. The thinking process is more important than the problem itself considering that Leetcode now has more than 1,000 problems(and the amount of problem is still growing at a fast speed) and it is inefficient to cover all the problems.

Who will not benefit much from this repo

You can not improve yourself much from this repo in a short time, say one month or so. If you do not have much time on coding preparation for your interview, I think it is better to practice the 'frequently asked questions' in leetcode, it will be more efficient.

How to use this repo to practice on your own

I suggest to practice according to category/tags, for example, DFS, BFS, Stack etc. And for each category, easy question first, then medium. You can check the difficulty and acceptance in leetcode website. And I recommend the following procedure for each problem:

  1. Look at the problem and think about some test cases, especially some edge case. Go through the test cases to ensure you fully understand the question.

  2. Come up with a solution, in this step, you do not begin to code, you just think it in your mind or write on papers. The solution should be specific and have details like the variables you want, data structure you use and the detail process. And then, use the test cases you have to check if it works. If you have no idea what to do, just try the brute force first, and then think about optimizing it. If you can not work out the solution in 20 minutes, do not waste more time on it, go to step 4! You can see the Solution.md, or you can go to discuss part on the leetcode or you can search some video on YouTube.

  3. Think about the solution you have once more to see if you can get a better algorithm, including smaller time complexity and smaller space complexity. Sometimes you have to sacrifice one to let the other one be better, think about why you do this. Think about it and calculate time complexity and space complexity. If this solution is not the best, go to step 2, continue to optimize it.

  4. You can now look at the Solution.md , have you consider all the edge cases in step 1? Then look at the algorithm I write, your methods may be better than me, or worse, you can compare the algorithms and review the thinking process. You can make some notes about what you did well and what you did not.

  5. Now you know all the cases you should deal with, you know how to work this problem out. Next, you need to do some coding stuff and see if you can pass all the test on leetcode. Be careful of the edge case and the conditions(For example, is it > or >=). Record your bugs, is it just a typo? Because when you are in this step, you have already know every algorithm and implementing details about this problem, your code should be clean and fast, and you should not have logic or other run time bugs. You may have some bugs related to language, that's ok, practice makes perfect.

  6. Review the problem if you can not work it out and use the optimal solution the first time after several days. If you can not work it out smoothly, do not feel frustrated, look at the part that block you from the right solution, take notes and think about it. After several days, try it again. I promise you will learn a lot in this step.

The more you practice and thinking, the less time you will spend in step 5, because coding is your instinct react at that time once you know how to do it. Along with the practice, you will gradually find that the problems look more and more similar, and the time you spend on solving problems is becoming less and less. If that happens, Congradulations!

Which language should I choose

In this repo, I choose C++. But you can choose whatever language you want. In my opinion, leetcode concentrates more on data structure and algorithm instead of language. Use your familiar language and just do it!

Thanks

Thanks for leetcode and leetcode forum. You can see all the problems and discussions in leetcode and practice online.

Releases

No releases published

Packages

No packages published

Languages