content: package utils;
  
  /**
   * @author jzy
   * @since 2024-01-05 11:15:54
   */
  public class ListNode {
  
      public int val;
      public ListNode next;
  
      ListNode() {
      }
  
      public ListNode(int val) {
          this.val = val;
      }
  
      public ListNode(int val, ListNode next) {
          this.val = val;
          this.next = next;
      }
  
      /**
       * 生成链表
       *
       * @param nums 数组
       * @return 链表头结点
       */
      public static ListNode genList(int[] nums) {
          ListNode head = new ListNode(nums[0]);
          ListNode cur = head;
          for (int i = 1; i < nums.length; i++) {
              cur.next = new ListNode(nums[i]);
              cur = cur.next;
          }
  
          return head;
      }
  
      /**
       * 打印链表
       *
       * @param head 链表头结点
       */
      public static void printList(ListNode head) {
          ListNode cur = head;
          while (cur != null) {
              System.out.print(cur.val + ", ");
              cur = cur.next;
          }
          System.out.println();
  
      }
  
      /**
       * 得到链表个数
       */
      public static int getSize(ListNode head) {
          ListNode cur = head;
          int size = 0;
          while (cur != null) {
              size++;
              cur = cur.next;
          }
          return size;
      }
  }
  