Try   HackMD
tags: leetcode

LeetCode の使い方

  • https://leetcode.com/ にアクセスする。

  • Problems を選択する。

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

  • 画面下部に問題が並んでいるので、Title を選択する(1. Two Sum を選択する例)。

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

  • 問題の画面が表示される(1. Two Sum の例)。

    • 画面左側に問題文が表示される。
    • 画面右側は、言語選択メニュー、回答入力エリア、実行ボタン(Run Code)、サブミットボタン(Submit)がある。
    • 実行・サブミットにはログインが必要。
      Image Not Showing Possible Reasons
      • The image file may be corrupted
      • The server hosting the image is unavailable
      • The image path is incorrect
      • The image format is not supported
      Learn More →

2022/2/20 現在選択できる言語

  • C++
  • Java
  • Python
  • Python3
  • C
  • C#
  • JavaScript
  • Ruby
  • Swift
  • Go
  • Scala
  • Kotlin
  • Rust
  • PHP
  • TypeScript
  • Racket
  • Erlang
  • Elixir
  • 問題文を読み解く(Two Sum の例)

    • 整数 nums の配列と整数 target が与えられたとき、2つの数値の足し算がtarget になるようなインデックスを返す。
      各入力は正確に1つの解を持つと仮定してよく、同じ要素を2度使ってはならない。
      答えはどのような順序でも返すことができる。
    • Example 1〜3 に具体的な例が記載されている。
    • Conftraints に条件が記載されている。
  • 回答入力エリアに関数の雛形が準備されているのでそれにあてはまる形でプログラムを記述していく。

    • Two Sum を Python3 で実行した例
    • 下部にある Use Example Testcases を選択すると、左画面にあるテストケースを入力全て入力してくれる。
    • Run Code で実行すると、Run Code Result に実行結果が表示される。
    • エラーがある場合はエラーメッセージが表示される。
      Image Not Showing Possible Reasons
      • The image file may be corrupted
      • The server hosting the image is unavailable
      • The image path is incorrect
      • The image format is not supported
      Learn More →
  • 回答が作成できたら、Submit を実行する。準備されている全てのテストケースが実行される。

    • 下の例は最初のサブミット(17:12)では、タイムアウトでエラーになってしまっている。
      Status の Time Limit Excedded のリンクに飛ぶとどのようなテストが失敗したのかを確認できる。右の回答画面に戻って失敗したテストケースが成功できるようになるまでプログラムを練り直す。
    • 次のサブミット(17:43)では、全てのテストが成功している。
      Image Not Showing Possible Reasons
      • The image file may be corrupted
      • The server hosting the image is unavailable
      • The image path is incorrect
      • The image format is not supported
      Learn More →
  • サブミットでのテストが成功すると Accepted のリンクから詳細を確認することができる。

    • 「あなたのランタイムは、python3の投稿の27.67%に勝っています。」ということなので、 Python3 で作った中でも遅いことがわかる。
      Image Not Showing Possible Reasons
      • The image file may be corrupted
      • The server hosting the image is unavailable
      • The image path is incorrect
      • The image format is not supported
      Learn More →
  • 左画面の Solution を選択すると、考え方と解答例を確認することができる。

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →