Giter Site home page Giter Site logo

bonfy / leetcode Goto Github PK

View Code? Open in Web Editor NEW
549.0 29.0 181.0 967 KB

:sparkles::v::sparkles:leetcode刷题 内附leetcode solution代码自动下载生成器(Leetcode solution auto generator)

Python 99.47% Rust 0.53%
leetcode leetcode-solutions python

leetcode's People

Contributors

bonfy avatar huangxuankun avatar wj2061 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

leetcode's Issues

建议将Leetcode solution auto generator与solutions分成两个repo

我对auto generator很感兴趣,希望能贡献力量做进一步优化。可是solutions和generator放在一起很不方便,因为每个人solutions都不一样,如果fork之后再pull很容易造成冲突。如果将两部分分开,可以方便地修改程序同时每个人又有独立的solutions。请考虑,谢谢。

mac os 10.12 执行报错

Selenium support for PhantomJS has been deprecated, please use headless versions of Chrome or Firefox instead
warnings.warn('Selenium support for PhantomJS has been deprecated, please use headless '
Traceback (most recent call last):
File "leetcode_generate.py", line 523, in
do_job(leetcode)
File "leetcode_generate.py", line 499, in do_job
leetcode.load()
File "leetcode_generate.py", line 234, in load
self.login()
File "leetcode_generate.py", line 190, in login
driver.find_element_by_id('id_remember').click()
File "/Users/guo/code/leetcode/venv/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 351, in find_element_by_id
return self.find_element(by=By.ID, value=id_)
File "/Users/guo/code/leetcode/venv/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 955, in find_element
'value': value})['value']
File "/Users/guo/code/leetcode/venv/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute
self.error_handler.check_response(response)
File "/Users/guo/code/leetcode/venv/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: {"errorMessage":"Unable to find element with id 'id_remember'","request":{"headers":{"Accept":"application/json","Accept-Encoding":"identity","Connection":"close","Content-Length":"92","Content-Type":"application/json;charset=UTF-8","Host":"127.0.0.1:56227","User-Agent":"Python http auth"},"httpVersion":"1.1","method":"POST","post":"{"using": "id", "value": "id_remember", "sessionId": "bbbd0580-1908-11e8-8373-630909998a7a"}","url":"/element","urlParsed":{"anchor":"","query":"","file":"element","directory":"/","path":"/element","relative":"/element","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/element","queryKey":{},"chunks":["element"]},"urlOriginal":"/session/bbbd0580-1908-11e8-8373-630909998a7a/element"}}
Screenshot: available via screen

当我把 driver.find_element_by_id('id_remember').click() 移除
并添加 driver.set_window_size(1920, 1080)
后就ok了

i think leetcode changes his website again

emmmmm....
the log as follows:
File ".\leetcode_generate.py", line 611, in <module> do_job(leetcode) File ".\leetcode_generate.py", line 588, in do_job leetcode.load() File ".\leetcode_generate.py", line 263, in load self.load_submissions() File ".\leetcode_generate.py", line 320, in load_submissions assert resp.status_code == 200 AssertionError
ORZ

self._load_solution_language() error

Leetcode login
Traceback (most recent call last):
line 461, in
main()
line 441, in main
leetcode.load()
line 247, in load
self._load_solution_language()
line 200, in _load_solution_language
assert r.status_code == 200
AssertionError

the py script is not work?

Error messages about Message: no such element: Unable to locate element: {"method":"id","selector":"id_login"}

Hi,
Thanks for your script and it saves my life to archive my solutions!
I tried to use the script to update my leetcode solution, and everytime I got the same error messages everytime as follows:
Traceback (most recent call last): File "leetcode_generate.py", line 603, in <module> do_job(leetcode) File "leetcode_generate.py", line 580, in do_job leetcode.load() File "leetcode_generate.py", line 253, in load self.login() File "leetcode_generate.py", line 205, in login driver.find_element_by_id('id_login').send_keys(usr) File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 351, in find_element_by_id return self.find_element(by=By.ID, value=id_) File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 955, in find_element 'value': value})['value'] File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute self.error_handler.check_response(response) File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"id","selector":"id_login"} (Session info: headless chrome=69.0.3497.100) (Driver info: chromedriver=2.37.544337 (8c0344a12e552148c185f7d5117db1f28d6c9e85),platform=Mac OS X 10.14.0 x86_64)
Any ideas about how to solve this issue?

Thanks,
Jiacheng

Locked problem with Leetcode Premium

Thanks for your script. I subscribed the Leetcode premium, however with this script, the locked problems still shows as locked. Can you please fix this?

python2.7+ubuntu

折腾了半天,终于跑通了,
环境:python2.7,ubuntu
中间出现了几个问题,记得的如下:
pip install futures;(python2.7)
在github上创建好repository,需要在linux下leetcode_generate.py代码目录先执行下git init
339行改成question = HTMLParser.HTMLParser().unescape(question) (python2.7, 需要先import HTMLParser)

No solution with the set languages in question

你好
我在使用脚本的时候遇到了一点问题
能获取我ac了的题目 但是下不下来

我leetcode上用的py写的
config里面填的

language = python,cpp

输出如下:

python3 leetcode_generate.py 
API load submissions request 2 seconds per request
Please wait ...
try to load submissions from  0  to  20
try to load submissions from  20  to  40
try to load submissions from  40  to  60
Leetcode load self info
download all leetcode solutions
No solution with the set languages in question:1-two-sum
No solution with the set languages in question:2-add-two-numbers
No solution with the set languages in question:11-container-with-most-water
No solution with the set languages in question:16-3sum-closest
No solution with the set languages in question:19-remove-nth-node-from-end-of-list
No solution with the set languages in question:21-merge-two-sorted-lists
No solution with the set languages in question:23-merge-k-sorted-lists
No solution with the set languages in question:24-swap-nodes-in-pairs
No solution with the set languages in question:41-first-missing-positive
No solution with the set languages in question:61-rotate-list
No solution with the set languages in question:82-remove-duplicates-from-sorted-list-ii
No solution with the set languages in question:83-remove-duplicates-from-sorted-list
No solution with the set languages in question:148-sort-list
No solution with the set languages in question:941-sort-array-by-parity
Leetcode finish dowload
Leetcode finish write readme
[master cc0ccc7] update at 2019-01-13
 1 file changed, 2 insertions(+), 2 deletions(-)
Username for 'https://github.com': 

谢谢

Cannot download the solution code from leetcode

Hi,
Thanks for this great tool, but I'm having a problem fetching the code solution from leetcode.

Here is the error logs:

...
begin download 013-roman-to-integer
encoding error : input conversion failed due to input error, bytes 0x21 0x00 0x00 0x00
begin download 015-3sum
encoding error : input conversion failed due to input error, bytes 0x21 0x00 0x00 0x00
begin download 016-3sum-closest
encoding error : input conversion failed due to input error, bytes 0x21 0x00 0x00 0x00
begin download 372-super-pow
encoding error : input conversion failed due to input error, bytes 0x21 0x00 0x00 0x00
begin download 419-battleships-in-a-board
encoding error : input conversion failed due to input error, bytes 0x21 0x00 0x00 0x00
begin download 461-hamming-distance
encoding error : input conversion failed due to input error, bytes 0x21 0x00 0x00 0x00
...

I'm using javascript btw.

注释优化 小建议

注释符号 根据 语言来区分,比如 python可以用 # ,C/C++/C#/Swift 等 就用 //

能否支持多种编程语言呢?

工具挺好用的, 先感谢作者.

但是请问能否支持多语言呢?
因为我用了多种语言(JS和JAVA)来刷leetcode,所以想爬取各种语言的代码.

Windows 环境报错

首先是这个issue
改了以后cookies.json生成了,但是碰到下面问题:

Traceback (most recent call last):
File "leetcode_generate.py", line 513, in
do_job(leetcode)
File "leetcode_generate.py", line 489, in do_job
leetcode.load()
File "leetcode_generate.py", line 235, in load
self.load_items_from_api()
File "leetcode_generate.py", line 220, in load_items_from_api
self.items = list(self._generate_items_from_api(rst))
File "leetcode_generate.py", line 248, in _generate_items_from_api
data['is_paid'] = json_data['is_paid']
KeyError: 'is_paid'
把is_paid注释掉,然后Line 143 改成

@property
    def is_lock(self):
        # return not self.is_paid and self.paid_only
        return self.paid_only

再跑就卡住不动了··好像是request连接超时··求解决下

run "python3 leetcode_generate.py" get back of these....

Traceback (most recent call last):
File "leetcode_generate.py", line 628, in
do_job(leetcode)
File "leetcode_generate.py", line 605, in do_job
leetcode.load()
File "leetcode_generate.py", line 268, in load
self.login()
File "leetcode_generate.py", line 209, in login
chrome_options=options, executable_path=executable_path
File "/home/levi/leetcode/venv/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 75, in init
desired_capabilities=desired_capabilities)
File "/home/levi/leetcode/venv/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 154, in init
self.start_session(desired_capabilities, browser_profile)
File "/home/levi/leetcode/venv/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 243, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/home/levi/leetcode/venv/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute
self.error_handler.check_response(response)
File "/home/levi/leetcode/venv/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary

sometimes it doesn’t work....

python leetcode_generate.py
sometimes when i execute the command, the output like follows:
[0907/225216.955:ERROR:gpu_process_transport_factory.cc(1016)] Lost UI shared context.

DevTools listening on ws://127.0.0.1:55206/devtools/browser/76b47762-659e-4df1-b801-95fb3b18b08d
[0907/225222.211:INFO:CONSOLE(1)] "lang "en" is not supported.", source: https://leetcode.com/static/webpack_bundles/common-libs.82d68e14.js (1)
[0907/225222.232:INFO:CONSOLE(1)] "lang "en" is not supported.", source: https://leetcode.com/static/webpack_bundles/common-libs.82d68e14.js (1)

it will stop here and do nothing then
my environment :win10 Chorme68.
But sometimes  it works. i don't know why....

support 4 digits problem ids

since the problems has exceeded 1000, it will be nice to pad an extra zero in the front

qname = '{id}-{title}'.format(id=str(qid).zfill(4), title=qtitle)

Only downloaded 6 problems for me

Hi, thanks for the generator!! It is really awesome!! However I came across the issue that I have 13 problems marked as solved on my Leetcode account. But the generator only downloaded 6 of them. Is there any specific parameter I need to adjust?

python脚本优化建议

  • 增加所有leetcode支持的语言。

  • Readme优化,目前只要是解决过的问题都会生成一个链接。
    应该限制为:解决过的问题并且是config设置的语言才生成链接。

报错WebDriverException

Traceback (most recent call last): File "leetcode_generate.py", line 627, in <module> do_job(leetcode) File "leetcode_generate.py", line 604, in do_job leetcode.load() File "leetcode_generate.py", line 267, in load self.login() File "leetcode_generate.py", line 210, in login driver.get(LOGIN_URL) File "/Users/zhangrong/anaconda/envs/py3/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 333, in get self.execute(Command.GET, {'url': url}) File "/Users/zhangrong/anaconda/envs/py3/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute self.error_handler.check_response(response) File "/Users/zhangrong/anaconda/envs/py3/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: unknown error: Runtime.executionContextCreated has invalid 'context': {"auxData":{"frameId":"93071366BB94A230ABBDCD535AED2AFC","isDefault":true,"type":"default"},"id":1,"name":"","origin":"://"} (Session info: chrome=73.0.3683.75) (Driver info: chromedriver=2.9.248307,platform=Mac OS X 10.14.3 x86_64)
谢谢大佬!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.