Description
Given a string containing only digits, restore it by returning all possible valid IP address combinations.
Example:
1 | Input: "25525511135" |
Thinking outside the box
A message containing letters from A-Z
is being encoded to numbers using the following mapping:
1 | 'A' -> 1 |
Given a non-empty string containing only digits, determine the total number of ways to decode it.
Example 1:
1 | Input: "12" |
Example 2:
1 | Input: "226" |
The gray code is a binary numeral system where two successive values differ in only one bit.
Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0.
Example 1:
1 | Input: 2 |
Example 2:
1 | Input: 0 |
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.
(i.e., [0,0,1,2,2,5,6]
might become [2,5,6,0,0,1,2]
).
You are given a target value to search. If found in the array return true
, otherwise return false
.
Example 1:
1 | Input: nums = [2,5,6,0,0,1,2], target = 0 |
Example 2:
1 | Input: nums = [2,5,6,0,0,1,2], target = 3 |
Follow up:
nums
may contain duplicates.Given a sorted array nums, remove the duplicates in-place such that duplicates appeared at most twice 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.
Example 1:
1 | Given nums = [1,1,1,2,2,3], |
Example 2:
1 | Given nums = [0,0,1,1,1,1,2,3,3], |
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 modification to the input array will be known to the caller as well.
Internally you can think of this:
1 | // nums is passed in by reference. (i.e., without making a copy) |
Given a 2D board and a word, find if the word exists in the grid.
The word can be constructed from letters of sequentially adjacent cell, where “adjacent” cells are those horizontally or vertically neighboring. The same letter cell may not be used more than once.
Example:
1 | board = |