Last active
March 29, 2019 20:15
-
-
Save yaodong/66c7527a64e832c9b68be1fb9174b942 to your computer and use it in GitHub Desktop.
leetcode problems list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'net/http' | |
require 'json' | |
require 'yaml' | |
url = URI('https://leetcode.com/api/problems/algorithms/') | |
res = Net::HTTP.get(url) | |
data = JSON.parse(res) | |
problems = data['stat_status_pairs'].map do |pair| | |
p = pair['stat'] | |
unless p['question__hide'] | |
{ | |
'id' => p['question_id'], | |
'title' => p['question__title'], | |
'url' => "https://leetcode.com/problems/#{p['question__title_slug']}/", | |
'slug' => p['question__title_slug'].gsub('-', '_') | |
} | |
end | |
end | |
problems.sort_by! { |p| p['id'] } | |
File.write('problems.yml', YAML.dump(problems)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment