[0,9]Explanation: Substrings starting at index 0 and 9 are "barfoo" and "foobar" respectively. The output order does not matter, returning [9,0] is fine too.
[0,9]Explanation: Substrings starting at index 0 and 9 are "barfoo" and "foobar" respectively. The output order does not matter, returning [9,0] is fine too.
Given two integers dividend and divisor, divide two integers without using multiplication, division and mod operator.
Return the quotient after dividing dividend by divisor.
The integer division should truncate toward zero, which means losing its fractional part. For example, truncate(8.345) = 8 and truncate(-2.7335) = -2.
EX:
Input: dividend = 7, divisor = -3
Output: -2
Explanation: 7/-3 = truncate(-2.33333..) = -2.
Implement strStr().
Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
EX:
Input: haystack = "hello", needle = "ll"
Output: 2 Input: haystack = "aaaaa", needle = "bba" Output: -1
Given an array nums and a value val, remove all instances of that value in-place and return 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.
EX:
Given nums = [0,1,2,2,3,0,4,2], val = 2,
Your function should return length = 5, with the first five elements of nums containing 0, 1, 3, 0, and 4. Note that the order of those five elements can be arbitrary. It doesn't matter what values are set beyond the returned length.
Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return 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.
EX:
Given nums = [0,0,1,1,1,2,2,3,3,4],
Your function should return length = 5, with the first five elements of nums being modified to 0, 1, 2, 3, and 4 respectively. It doesn't matter what values are set beyond the returned length.
1->2->3->4->5 For k = 2, you should return: 2->1->4->3->5
For k = 3, you should return: 3->2->1->4->5
Given a linked list, swap every two adjacent nodes and return its head.
You may not modify the values in the list's nodes, only nodes itself may be changed.
EX:
Given 1->2->3->4, you should return the list as 2->1->4->3.
[ 1->4->5, 1->3->4, 2->6 ] Output: 1->1->2->3->4->4->5->6
"((()))", "(()())", "(())()", "()(())", "()()()" ]
Output: 1->1->2->3->4->4
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.
An input string is valid if:
Note that an empty string is also considered valid.
EX:
Input: "()[]{}"
Output: true
Input: "([)]"Output: false
Given a linked list, remove the n-th node from the end of list and return its head.
EX:
Given linked list: 1->2->3->4->5, and n = 2.
After removing the second node from the end, the linked list becomes 1->2->3->5.
Note:
Given n will always be valid.
Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"].