convert an array to a linked list

tags: learning programming leetcode

content

  • when converting
  • array: nums = [1, 2, 3, 2]
  • we need to treat each element of the array as a index, value pair
    • where index is the value of the ListNode, and value is the next ListNode it points to

      leetcode-array-to-linked-list 2026-01-16 15.56.20.excalidraw

      ⚠ Switch to EXCALIDRAW VIEW in the MORE OPTIONS menu of this document. ⚠ You can decompress Drawing data with the command palette: ‘Decompress current Excalidraw file’. For more info check in plugin settings under ‘Saving’

      Excalidraw Data

      Text Elements

      1

      2

      0

      3

      [1, 2, 3, 2, 2]

      there’re three 2s in the array, therefore, there’re three nodes pointing to the node with value 2

      4

      Link to original

up

down

reference