• Stars
    star
    214
  • Rank 184,678 (Top 4 %)
  • Language
    Python
  • Created about 8 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

leetcode solution by python

leetcode python solution

Algorithms

(💯 代表答主提交答案时在前 100 %)

1. Two Sum: Solution

2. Add Two Numbers: Solution 💯

3. Longest Substring Without Repeating Characters: Solution

4. Median of Two Sorted Arrays: Solution 💯

5. Longest Palindromic Substring: Solution

(这道题对 Python 有毒, 只要时间复杂度大于等于 O(n2) 绝对 TLE, 其它语言 O(n3) 也能过...)

tips: Python 用 Manacher’s Algorithm 比较稳, 其它算法基本 TLE. 本例里用将每个字符当作回文串中心对匹配方式,还是可能 TLE.

6. ZigZag Conversion:Solution

tips: 以每 (2 * numRows - 2) 个字符串为一组进行操作,最后一组不足 (2 * numRows - 2) 个字符用特殊字符补齐,最后返回前再将特殊字符去掉

7. Reverse Integer: Solution

8. String to Integer (atoi): Solution

9. Palindrome Number: Solution

10. Regular Expression Matching: Solution

tips: 用动态规划的思路可以解, 递归 Python 会 TLE. 用 re 库可以一句话解决: (return re.match(r'^{0}$'.format(p), s)) 不过不推荐.

11. Container With Most Water: Solution 💯

tips: bf 做复杂度 O(n2) Python 会 TLE. 用两个游标分别从数组首位出发谁小谁移动, 纪录其中最大值, 复杂度 O(n)

12. Integer to Roman: Solution

13. Roman to Integer: Solution 💯

14. Longest Common Prefix: Solution

动态规划思路: 复杂度 O(n2), 状态是: n 个字符串 n <= len(strs) 的最长公共前缀, 转移方程: D(n) = min{D(n-1), L(j)}, 0 <= j <= min{D(n-1), len(str(n))} (大概是这样)

15. 3Sum: Solution

tips: K Sum Problem

16. 3Sum Closest: Solution

tips: 可以看作是有个固定数字的 4 Sum 问题,稍微改下 3 Sum 代码即可, 时间复杂度不增加 O(nlogn)

17. Letter Combinations of a Phone Number: Solution

tips: 简单替换后直接算 kronecker 积, 复杂度 O(n)

18. 4Sum: Solution

19. Remove Nth Node From End of List: Solution

20. Valid Parentheses: Solution

21. Merge Two Sorted Lists: Solution

22. Generate Parentheses: Solution

tips: backtracking

23. Merge k Sorted Lists: Solution

tips: 分治法 归并排序

24. Swap Nodes in Pairs: Solution

25. Reverse Nodes in k-Group: Solution

26. Remove Duplicates from Sorted Array: Solution

tips1: 虽然只是让返回去除重复后的数组长度,但是oj还是会判断代码是否真的去掉的是重复的元素,否则即使你返回的长度正确oj依然会 WA
tips2: 不能用len(set(nums)) 一句完成,因为 set 申请了新的空间,而题目要求不能使用新的空间

27. Remove Element: Solution

28. Implement strStr(): Solution

29. Divide Two Integers: Solution

More Repositories

1

wechat_sender

随时随地发送消息到微信
Python
465
star
2

django-vue.js-blog

django-vue.js-blog
Python
262
star
3

django-simple-serializer

serialize django data in a simple way
Python
155
star
4

hellspawn-hunter-weapp

hellspawn-hunter-weapp
JavaScript
77
star
5

HellspawnHunterBackend

HellspawnHunterBackend
JavaScript
50
star
6

django-angularjs-blog

A simple blog site powered by django + angularjs
Python
29
star
7

multithreading-spider

a simple demo use threading and queue get proxies from proxy sites
Python
18
star
8

django-redis-doc-chs

django-redis-doc-chs
JavaScript
17
star
9

DecentralAdPlatform

DecentralAdPlatform
JavaScript
8
star
10

simple_wsgi_server

simple_wsgi_server
Python
8
star
11

Alinone

combine
Python
3
star
12

tornado-chatdemo-with-room

tornado-chatdemo-with-room
Python
2
star
13

LeadYouFly

LeadYouFly
JavaScript
2
star
14

chat-room-websocket

chat-room-websocket
Python
1
star
15

Django-AngularJS2

Django-AngularJS2 Demo
JavaScript
1
star
16

mb_project

mb_project
Python
1
star
17

E-SITE

E-SITE
1
star
18

shadow

shadow
Python
1
star
19

smart_screen

Python
1
star
20

ESite

ESite
1
star
21

zhz

zhz
Python
1
star
22

show

show
HTML
1
star
23

Phorcys

Phorcys
Python
1
star
24

smart_clound

smart_clound
Python
1
star
25

wechat_server

wechat_server
JavaScript
1
star
26

learngit

learngit
1
star
27

lighthouse

lighthouse
JavaScript
1
star
28

pic

pic
1
star
29

lg_data

lg_data
Python
1
star
30

dogedoge

dogedoge
Python
1
star
31

tornado-layered-router

provide a layered url router like django router to tornado
Python
1
star
32

magic_conch

magic_conch
Shell
1
star
33

Riddle

Riddle
Python
1
star
34

HouseParty

HouseParty
JavaScript
1
star
35

riddle_common

riddle_common
Python
1
star
36

ooil

ooil
JavaScript
1
star
37

bit-sentry

bit-sentry
Python
1
star