Total Accepted: 88409
Total Submissions: 321579
Difficulty: Easy
Write a function to find the longest common prefix string amongst an array of strings.
select * from utils
Total Accepted: 88409
Total Submissions: 321579
Difficulty: Easy
Write a function to find the longest common prefix string amongst an array of strings.
Total Accepted: 53495
Total Submissions: 191288
Difficulty: Easy
Remove all elements from a linked list of integers that have value val.
Example
Given: 1 –> 2 –> 6 –> 3 –> 4 –> 5 –> 6, val = 6
Return: 1 –> 2 –> 3 –> 4 –> 5
Credits:
Special thanks to @mithmatt for adding this problem and creating all test cases.
Total Accepted: 72708
Total Submissions: 258534
Difficulty: Easy
The count-and-say sequence is the sequence of integers beginning as follows:
1, 11, 21, 1211, 111221, ...
1
is read off as "one 1"
or 11
.
11
is read off as "two 1s"
or 21
.
21
is read off as "one 2
, then one 1"
or 1211
.
Given an integer _n_, generate the _n_th sequence.
Note: The sequence of integers will be represented as a string.
Total Accepted: 27238
Total Submissions: 96500
Difficulty: Easy
Given a pattern
and a string str
, find if str
follows the same pattern.
Here follow means a full match, such that there is a bijection between a letter in pattern
and a non-empty word in str
.
Examples:
pattern = "abba"
, str = "dog cat cat dog"
should return true.
pattern = "abba"
, str = "dog cat cat fish"
should return false.
pattern = "aaaa"
, str = "dog cat cat dog"
should return false.
pattern = "abba"
, str = "dog dog dog dog"
should return false.
Notes:
You may assume pattern
contains only lowercase letters, and str
contains lowercase letters separated by a single space.
Total Accepted: 95596
Total Submissions: 332615
Difficulty: Easy
Given a string containing just the characters '('
, ')'
, '{'
, '}'
, '['
and ']'
, determine if the input string is valid.
The brackets must close in the correct order, "()"
and "()[]{}"
are all valid but "(]"
and "([)]"
are not.
Total Accepted: 47679
Total Submissions: 165936
Difficulty: Easy
Given two strings _s_ and _t_, determine if they are isomorphic.
Two strings are isomorphic if the characters in _s_ can be replaced to get _t_.
All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character but a character may map to itself.
For example,
Given "egg"
, "add"
, return true.
Given "foo"
, "bar"
, return false.
Given "paper"
, "title"
, return true.
Note:
You may assume both _s_ and _t_ have the same length.
Total Accepted: 20108
Total Submissions: 70200
Difficulty: Easy
You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide a hint that indicates how many digits in said guess match your secret number exactly in both digit and position (called “bulls”) and how many digits match the secret number but locate in the wrong position (called “cows”). Your friend will use successive guesses and hints to eventually derive the secret number.
For example:
Secret number: "1807" Friend's guess: "7810"
Hint: 1
bull and 3
cows. (The bull is 8
, the cows are 0
, 1
and 7
.)
Write a function to return a hint according to the secret number and friend’s guess, use A
to indicate the bulls and B
to indicate the cows. In the above example, your function should return "1A3B"
.
Please note that both secret number and friend's guess may contain duplicate digits, for example:
Secret number: "1123" Friend's guess: "0111"
In this case, the 1st 1
in friend’s guess is a bull, the 2nd or 3rd 1
is a cow, and your function should return "1A1B"
.
You may assume that the secret number and your friend’s guess only contain digits, and their lengths are always equal.
Total Accepted: 96063
Total Submissions: 333812
Difficulty: Easy
Given a linked list, remove the _n_th node from the end of list and return its head.
For example,
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.
Try to do this in one pass.
Total Accepted: 83878
Total Submissions: 291685
Difficulty: Easy
Given a string _s_ consists of upper/lower-case alphabets and empty space characters ' '
, return the length of last word in the string.
If the last word does not exist, return 0.
Note: A word is defined as a character sequence consists of non-space characters only.
For example,
Given _s_ = "Hello World"
, return 5
.
Total Accepted: 54042
Total Submissions: 185450
Difficulty: Easy
Reverse bits of a given 32 bits unsigned integer.
For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 00111001011110000010100101000000).
Follow up:
If this function is called many times, how would you optimize it?
Related problem: Reverse Integer