Skip to content

Instantly share code, notes, and snippets.

@yaodong
Last active March 29, 2019 20:15
Show Gist options
  • Save yaodong/66c7527a64e832c9b68be1fb9174b942 to your computer and use it in GitHub Desktop.
Save yaodong/66c7527a64e832c9b68be1fb9174b942 to your computer and use it in GitHub Desktop.
leetcode problems list
#!/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