リスト操作の基礎: 要素の削除、リストの設計、およびリストの逆転
リスト理論の基礎
リストノードの定義
class ListNode:
def __init__(self, val=0, next=None):
self.val = val
self.next = next
203. リストから要素を削除する
class Solution:
def removeElements(self, head, val):
dummy_head = ListNode(next=head)
current = dummy_head
while current.next is not None:
...
7月16日 21:47 投稿
文字配列の反転操作
問題概要
文字配列を反転させる関数を実装します。入力は文字配列 s で、以下の条件を満たす必要があります:
追加の配列を割り当てない
入力配列をその場で変更
O(1) の追加メモリのみ使用
入力例
<strong>入力:</strong>s = ["h","e","l","l","o"]
<strong>出力:</strong>["o","l","l","e","h"]
<strong>入力:</strong>s = [" ...
6月27日 01:32 投稿