0% found this document useful (0 votes)
86 views

Example 1:: 1. Two Sum

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 return the answer in any order and may not use the same element twice.

Uploaded by

gobichand7
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views

Example 1:: 1. Two Sum

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 return the answer in any order and may not use the same element twice.

Uploaded by

gobichand7
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

**********

1. Two Sum
**********

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:

Input: nums = [3,2,4], target = 6


Output: [1,2]

Example 3:

Input: nums = [3,3], target = 6


Output: [0,1]

Constraints:

2 <= nums.length <= 103


-109 <= nums[i] <= 109
-109 <= target <= 109
Only one valid answer exists.

******************
7. Reverse Integer
******************

Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes the value to go outside the signed 32-
bit integer range [-231, 231 - 1], then return 0.

Assume the environment does not allow you to store 64-bit integers (signed or unsigned).

Example 1:

Input: x = 123
Output: 321

Example 2:
Input: x = -123
Output: -321

Example 3:

Input: x = 120
Output: 21

Example 4:

Input: x = 0
Output: 0

Constraints:

-231 <= x <= 231 - 1

********************
9. Palindrome Number
********************

Given an integer x, return true if x is palindrome integer.

An integer is a palindrome when it reads the same backward as forward. For example, 121 is palindrome while 123 is not.

Example 1:

Input: x = 121
Output: true

Example 2:

Input: x = -121
Output: false
Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a
palindrome.

Example 3:

Input: x = 10
Output: false
Explanation: Reads 01 from right to left. Therefore it is not a palindrome.

Example 4:

Input: x = -101
Output: false
Constraints:

-231 <= x <= 231 - 1

Follow up: Could you solve it without converting the integer to a string?

*********************
20. Valid Parentheses
*********************

Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.

An input string is valid if:

1. Open brackets must be closed by the same type of brackets.


2. Open brackets must be closed in the correct order.

Example 1:

Input: s = "()"
Output: true

Example 2:

Input: s = "()[]{}"
Output: true

Example 3:

Input: s = "(]"
Output: false

Example 4:

Input: s = "([)]"
Output: false

Example 5:

Input: s = "{[]}"
Output: true

Constraints:

1 <= s.length <= 104


s consists of parentheses only '()[]{}'.
**************************
21. Merge Two Sorted Lists
**************************

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:

Input: l1 = [], l2 = [0]


Output: [0]

Constraints:

The number of nodes in both lists is in the range [0, 50].


-100 <= Node.val <= 100
Both l1 and l2 are sorted in non-decreasing order.

***************************************
26. Remove Duplicates from Sorted Array
***************************************

You might also like