[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"searchBlogPosts":3,"$faSZq5VhVo-G4UXttY1rUtPrV_vZ_HVrn3F85ou1u3C4":7},[4],{"_path":5,"title":6},"\u002Fblog\u002F2023\u002F09\u002F17\u002Fspring-boot-postgresql","Spring Boot with PostgreSQL & pgAdmin in Docker",{"title":8,"category":9,"problemHtml":10,"solutions":11,"repoUrl":20},"Linked List Cycle Detection","Data Structures & Algorithms","",[12,16],{"lang":13,"label":14,"html":15},"java","Java","\u003Cpre>\u003Ccode class=\"language-java\">\u002F**\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 *\u002F\n\nclass Solution {\n    public boolean hasCycle(ListNode head) {\n        HashSet&lt;ListNode&gt; seen = new HashSet&lt;&gt;();\n\n        ListNode curr = head;\n        while(curr != null){\n            if(seen.contains(curr)){\n                return true;\n            }\n\n            seen.add(curr);\n            curr = curr.next;\n        }\n\n        return false;\n    }\n}\u003C\u002Fcode>\u003C\u002Fpre>",{"lang":17,"label":18,"html":19},"python","Python","\u003Cpre>\u003Ccode class=\"language-python\"># Definition for singly-linked list.\n# class ListNode:\n#     def __init__(self, val=0, next=None):\n#         self.val = val\n#         self.next = next\n\nclass Solution:\n    def hasCycle(self, head: Optional[ListNode]) -&gt; bool:\n        slow, fast = head, head\n\n        while fast and fast.next:\n            slow = slow.next\n            fast = fast.next.next\n            if slow == fast:\n                return True \n        \n        return False\u003C\u002Fcode>\u003C\u002Fpre>","https:\u002F\u002Fgithub.com\u002Fvishwarajsali\u002FInterviewPrep\u002Ftree\u002Fmain\u002FData%20Structures%20%26%20Algorithms%2Flinked-list-cycle-detection"]