Templates and examples in Python3, including common data structure & algorithms.
I have collected and summarized general code templates for particular algorithms, and add most typical examples to help make better use of it. All the examples come from LeetCode, and I have attached the problem id and brief description.
"Stop Trying to Reinvent the Wheel"
So I try my best to find the commonality in problems, solutions and codes. When I study, I have summarized templates for future use.
First I intended to use it for myself, and now I realize maybe it is good enough to share with people who also need it.
It is written in Python3, but easy to extend to other languages, such as Java, C++. Just replace the python syntactic sugar and advanced tricks, maybe just less concise.
With my limited time and ability, here only covers common data structure & algorithms. Almost suitable for interview, but insufficient for competition.
I have tried my best to collect and summarize the most general and best-practice templates in particular area, but this version may not be the best solution. Or, it's really the best performance and most concise solution, but it's not the suitable for you. Within acceptable performance, it is the best practice for you when you use it most conveniently.
Code templates is written by python with some pseudo code, so I use self
and add stub functions to pass compiler's check. You should replace them with your particular logic according to the comments.
"life is short, you need python"
With the help of Python's advanced features, it can let us ignore redundant grammar, and totally focus on algorithm and logic.
Besides, it is popular, and I'm the big fan of this language myself.
Feel free to use, copy, modify, merge or publish. just add a reference, please.
If it helps you or you like it, you can star or share it. thanks : )
I'm glad if you want to contribute to make it better.
I scrape the most popular discussions and filter the ones which summarized a general approach to particular domain, such as backtracking, dynamic programming, sliding window, bit manipulation.
Well worth reading:
sliding window
bit manipulation
dynamic programming
solving array-related problems
binary tree traversal
backtracking
bitwise operation for single numbers
recnac@foxmail.com