This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. | |
| You may assume that each input would have exactly one solution, and you may not use the same element twice. | |
| You can return the answer in any order. | |
| Example 1: | |
| Input: nums = [2,7,11,15], target = 9 | |
| Output: [0,1] | |
| Output: Because nums[0] + nums[1] == 9, we return [0, 1]. | |
| Example 2: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Given a string s, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. | |
| Example 1: | |
| Input: s = "A man, a plan, a canal: Panama" | |
| Output: true | |
| Explanation: "amanaplanacanalpanama" is a palindrome. | |
| Example 2: | |
| Input: s = "race a car" | |
| Output: false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. | |
| An input string is valid if: | |
| Open brackets must be closed by the same type of brackets. | |
| Open brackets must be closed in the correct order. | |
| Example 1: | |
| Input: s = "()" | |
| Output: true | |
| Example 2: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Given an m x n grid of characters board and a string word, return true if word exists in the grid. | |
| The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically neighboring. The same letter cell may not be used more than once. | |
| Example 1: | |
| Input: board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "ABCCED" | |
| Output: true | |
| Example 2: | |
| Input: board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "SEE" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list. | |
| You may assume the two numbers do not contain any leading zero, except the number 0 itself. | |
| Example 1: | |
| Input: l1 = [2,4,3], l2 = [5,6,4] | |
| Output: [7,0,8] | |
| Explanation: 342 + 465 = 807. | |
| Example 2: | |
| Input: l1 = [0], l2 = [0] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list. | |
| You may assume the two numbers do not contain any leading zero, except the number 0 itself. | |
| Example 1: | |
| Input: l1 = [7,2,4,3], l2 = [5,6,4] | |
| Output: [7,8,0,7] | |
| Example 2: | |
| Input: l1 = [2,4,3], l2 = [5,6,4] | |
| Output: [8,0,7] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Given a sorted array nums, remove the duplicates in-place such that each element appears only once and returns the new length. | |
| Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory. | |
| Clarification: | |
| Confused why the returned value is an integer but your answer is an array? | |
| Note that the input array is passed in by reference, which means a modification to the input array will be known to the caller as well. | |
| Internally you can think of this: | |
| // nums is passed in by reference. (i.e., without making a copy) | |
| int len = removeDuplicates(nums); | |
| // any modification to nums in your function would be known by the caller. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| 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 continuously following the next pointer. Internally, pos is used to denote the index of the node that tail's next pointer is connected to. Note that pos is not passed as a parameter. | |
| Return true if there is a cycle in the linked list. Otherwise, return false. | |
| Example 1: | |
| Input: head = [3,2,0,-4], pos = 1 | |
| Output: true | |
| Explanation: There is a cycle in the linked list, where the tail connects to the 1st node (0-indexed). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Merge two sorted linked lists and return it as a sorted list. The list should be made by splicing together the nodes of the first two lists. | |
| Example 1: | |
| Input: l1 = [1,2,4], l2 = [1,3,4] | |
| Output: [1,1,2,3,4,4] | |
| Example 2: | |
| Input: l1 = [], l2 = [] | |
| Output: [] | |
| Example 3: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Given the head of a singly linked list, reverse the list, and return the reversed list. | |
| Example 1: | |
| Input: head = [1,2,3,4,5] | |
| Output: [5,4,3,2,1] | |
| Example 2: | |
| Input: head = [1,2] | |
| Output: [2,1] | |
| Example 3: |