Skip to content

Latest commit

 

History

History
130 lines (91 loc) · 4.74 KB

how-to-leetcode.md

File metadata and controls

130 lines (91 loc) · 4.74 KB

How to Leetcode

Menu:


This article will not talk about how to solve Two Sum or other leetcode problems. I write this article to share my opinion of solving leetcode problems.

Though title is 'how to leetcode', and you can change the 'leetcode' to other online judge problems.

I have solved 200+ leetcode problems and share them in my github and CSDN blog (writen in Chinese). Today a guy messaged me for how to solve the leetcode problems. Because of the terrible messaging system I cannot talk to him easily. So I try to write down this page to talk about it.

But I am not so clever and words may sometimes naive. If there was something wrong please tell me.

Why Solve

Why you want to solve these algorithm problems in leetcode?

  1. improve algorithms
  2. hack the interview
  3. not fuck off by google (just solve invert binary tree)
  4. it's cool (show to your friends)

Material

Where to find the material of leetcode problems? Such as solution, analysis discuss.

  1. github
    There are lots of solutions in githubs. It say, "We’ve found 8,754 repository results".
    Just choose one or two nice repository to learn.
  2. Leetcode Discuss
    Click the 'Discuss' button in problem page and you can see it.
    You can find many solutions and discussions of this problem. Try to ask a question if you have trouble solving it.
  3. google
    Google can do anything.

Order

You can solve the problems from easy to hard, by acceptance, or by id. You can sort the problems in the list page.

But there are some series problems, such as 'Contains Duplicate', 'Contains Duplicate II', 'Contains Duplicate III'. Later ones always base on privious. So remember to solve them in order.

Steps

This is main dishes.

  1. read carefully
    • Read once more
    • Try to write the key words and process in paper
    • Find similar problems in brain
  2. think out a simulation or brute force solution
    • Ignore the time and space complexity, how to solve it
    • Talk the solution to self or others
  3. think about optimizing it
    • Is the solution above terrible? (Cannot accepted)
    • Can the terrible solution be optimized (time and space usage)? How?
  4. check the 'tags'
    • Click the 'Show Tags'.
    • It will help you
  5. check discussion titles
    • If you even cannot solve it after 4 steps, just leave computer and have a break. And think again.
    • Check title but not content in Leetcode Discuss, and think again.
  6. see discussion content or github problem notes
    • If you even cannot solve it after 4 steps, just leave computer and have a break. And think again.
    • See others notes but not code. Solve the problem.
    • If you have trouble solving problems, just ask a question in Leetcode Discuss.
  7. find out more ways to solve it
    • After solve it, find different idea in discussion, github and Google.
    • Image how others can come out with these ideas.
  8. compare different solutions
    • Analysis time and space complexity of these solutions, find out the best one.
    • If there is a faster solution just solve it out.
    • (Think) How to write them bug free?

After getting accepted, don't close the page.
Just finish 7 and 8 steps, and you can get more technologe beyond the problems.

Point

Catch these points when solving problems:

  • fast
  • right
  • bug free
  • debug skill
  • analysis
  • language features
  • *test case
  • *talk out

Share notes

  • Try to share your opinion with others, such as your friends and discuss.
  • If you have a nice solution, share it to the Leetcode Discuss.
  • Other people will ask questions help others, help them.
  • After solve problems, sort them by your own tags.
  • Write articles, notes in your blog and github. (like me) And you can review problems by them.

Primium? Book?

Some people think after paying a fee they will work harder.
Maybe it's true. But I didn't spend any money.
Because there is enough free problems to practice. Without 'leetcode book' I can think more and get multiple solutions in discussion.

If you done all free problems you can try following:

  • rewrite old problems
  • talk about the problems to your friends
  • guess the fee problems from title :)

I am not advanced player in LeetCode. I just share my simple opinion about LeetCode. If there is something wrong, feel free creating issues or contacting me.