Merge Two Sorted Lists
You are given the heads of two sorted linked lists. Merge them into one sorted list by splicing together the nodes, and return the head of the merged list.
click to see solutionSummary Ranges
Given a sorted array of unique integers, return the smallest sorted list of ranges that cover every number exactly. Write a range as "a->b", or just "a" if it is a single number.
click to see solutionHappy Number
A number is happy if repeatedly replacing it with the sum of the squares of its digits eventually reaches 1. If it never reaches 1, it loops endlessly. Return true if n is a happy number.
click to see solutionN-Queens
Place n queens on an n x n chessboard so that no two queens attack each other, meaning no two share a row, column, or diagonal. Return all distinct solutions.
click to see solutionRansom Note
Given two strings ransomNote and magazine, return true if ransomNote can be constructed using the letters from magazine, and false otherwise. Each letter in magazine can only be used once.
click to see solutionLinked List Cycle
Given the head of a linked list, determine if the linked list has a cycle in it. There is a cycle if some node can be reached again by continuously following the next pointer. Return true if there is a cycle, otherwise return false.
click to see solutionLongest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty string.
click to see solutionMajority Element
Given an array of size n, return the majority element. The majority element is the element that appears more than ⌊n / 2⌋ times. You may assume that the majority element always exists in the array.
click to see solution