Stackクラス

この演習では、Stack クラスを実装していただきます。このクラスには次のような機能が必要です:

  1. スタックにアイテムを追加する (push() メソッド)

  2. スタックからアイテムを取り出す (pop() メソッド) - 取り出したアイテムを削除して返す

  3. スタックが空かどうかを確認する (is_empty() メソッド) - 真偽値を返す

入力

出力

s = Stack(); s.push(1); s.push(2); s.push(3); print(s.pop()); print(s.is_empty()); print(s.pop()); print(s.pop()); print(s.is_empty())

3 False 2 1 True

Constraints

Time limit: 2 seconds

Memory limit: 512 MB

Output limit: 1 MB

To check your solution you need to sign in
Sign in to continue