Computer Science, asked by abbasist9613, 1 year ago

Given a linked list, return the node where the cycle begins.

Answers

Answered by abhi3023
3

Answer:

ɢɪᴠᴇɴ ᴀ sɪɴɢʟʏ ʟɪɴᴋᴇᴅ ʟɪsᴛ, ғɪɴᴅ ᴍɪᴅᴅʟᴇ ᴏғ ᴛʜᴇ ʟɪɴᴋᴇᴅ ʟɪsᴛ. 

ғᴏʀ ᴇxᴀᴍᴘʟᴇ, ɪғ ɢɪᴠᴇɴ ʟɪɴᴋᴇᴅ ʟɪsᴛ ɪs 1->2->3->4->5 ᴛʜᴇɴ ᴏᴜᴛᴘᴜᴛ sʜᴏᴜʟᴅ ʙᴇ 3.

 ɪғ ᴛʜᴇʀᴇ ᴀʀᴇ ᴇᴠᴇɴ ɴᴏᴅᴇs, ᴛʜᴇɴ ᴛʜᴇʀᴇ ᴡᴏᴜʟᴅ ʙᴇ ᴛᴡᴏ ᴍɪᴅᴅʟᴇ ɴᴏᴅᴇs, ᴡᴇ ɴᴇᴇᴅ ᴛᴏ ᴘʀɪɴᴛ sᴇᴄᴏɴᴅ ᴍɪᴅᴅʟᴇ ᴇʟᴇᴍᴇɴᴛ. ғᴏʀ ᴇxᴀᴍᴘʟᴇ, ɪғ ɢɪᴠᴇɴ ʟɪɴᴋᴇᴅ ʟɪsᴛ ɪs 1->2->3->4->5->6 ᴛʜᴇɴ ᴏᴜᴛᴘᴜᴛ sʜᴏᴜʟᴅ ʙᴇ 4.

Similar questions