Leetcode 0202. Happy Number

Posted on Mon 18 November 2024 in Leetcode • Tagged with set, fast-slow-pointer

Question Link : https://leetcode.com/problems/happy-number/

Difficulty: Easy

Premium: False

Question

Write an algorithm to determine if a number n is happy. A happy number is a number defined by the following process:

Starting with any positive integer, replace the number by the sum of the squares of its …


Continue reading

Leetcode 0876. Middle of the Linked List

Posted on Sun 04 December 2022 in Leetcode • Tagged with fast-slow-pointer

Question Link : https://leetcode.com/problems/middle-of-the-linked-list/

Difficulty: Easy

Premium: False

Question

Given the head of a singly linked list, return the middle node of the linked list. If there are two middle nodes, return the second middle node.   Example 1:

Input: head = [1,2,3,4,5] Output: [3 …


Continue reading

Leetcode 0234. Palindrome Linked List

Posted on Sat 29 October 2022 in Leetcode • Tagged with palindrome-center-expansion, fast-slow-pointer

Question Link : https://leetcode.com/problems/palindrome-linked-list/

Difficulty: Easy

Question

Given the head of a singly linked list, return true if it is a palindrome or false otherwise.   Example 1:

Input: head = [1,2,2,1] Output: true

Example 2:

Input: head = [1,2] Output: false

Constraints:

The number of …


Continue reading

Leetcode 2095. Delete the Middle Node of a Linked List

Posted on Thu 13 October 2022 in Leetcode • Tagged with fast-slow-pointer

Question Link : https://leetcode.com/problems/delete-the-middle-node-of-a-linked-list/

Difficulty: Medium

Question

You are given the head of a linked list. Delete the middle node, and return the head of the modified linked list. The middle node of a linked list of size n is the ⌊n / 2⌋th node from the …


Continue reading

Leetcode 0141. Linked List Cycle

Posted on Mon 07 March 2022 in Leetcode • Tagged with linked-list, fast-slow-pointer

Question Link : https://leetcode.com/problems/linked-list-cycle/

Difficulty: Easy

Question

Given head, the head of a linked list, determine if the linked list has a cycle in it. There is a cycle in a linked list if there is some node in the list that can be reached again by …


Continue reading