Recursion
Intuition\nFind the length of a linked list then based on the quotient and the reminder point the reference of a linkedlist to a resultant linked list.\n Descri
# Intuition\nFind the length of a linked list then based on the quotient and the reminder point the reference of a linkedlist to a resultant linked list.\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nRecursive solution\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(n + n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n/**\n * Definition for singly-linked list.\n * public class ListNode {\n *     int val;\n *     ListNode next;\n *     ListNode() {}\n *     ListNode(int val) { this.val = val; }\n *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n    public ListNode[] splitListToParts(ListNode head, int k) {\n        int length = length(head);\n        ListNode[] nodes = new ListNode[k];\n        nodes[0] = head;\n        int q = length / k;\n        int r = length % k;\n        recursion(head,1,r,q,nodes,1);\n        return   nodes;\n    }\n    private int length(ListNode head){\n        if(head==null) return 0;\n        else return 1 + length(head.next);\n    }\n    private void recursion(ListNode node ,int i, int r,int q, ListNode[] nodes,int index){\n        if(index>=nodes.length || node==null) return;\n        if(q==0 || i%q==0){\n            if(q==0){\n                ListNode temp = node.next;\n                node.next = null;\n                nodes[index] = temp;\n                recursion(temp,1,r-1,q,nodes,index+1);   \n            }\n            else if(r==0){\n                ListNode temp = node.next;\n                node.next = null;\n                nodes[index] = temp;\n                recursion(temp,1,r,q,nodes,index+1);   \n            }\n            else if(r>0){\n                ListNode temp = node.next.next;\n                node.next.next = null;\n                nodes[index] = temp;\n                recursion(temp,1,r-1,q,nodes,index+1);     \n            }\n        }else{\n             recursion(node.next,i+1,r,q,nodes,index);   \n        }\n    } \n}\n```
['Linked List', 'Recursion', 'Java']