Problem
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly one solution. Continue reading
Category Archives: Algorithms
3Sum – LeetCode
Problem
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.
Continue reading
Palindrome Number – LeetCode
Problem
Determine whether an integer is a palindrome. Do this without extra space.
Some hints:
1. Could negative integers be palindromes? (ie, -1)
2. If you are thinking of converting the integer to string, note the restriction of using extra space.
3. You could also try reversing an integer. However, if you have solved the problem “Reverse Integer”, you know that the reversed integer might overflow. How would you handle such case?
Continue reading
String to Integer (atoi) – LeetCode
Problem
Implement atoi to convert a string to an integer.
1 2 3 4 5 6 |
public class Solution { public int atoi(String str) { } } |
Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input cases. Continue reading
Reverse Integer – LeetCode
Problem:
Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321 Continue reading
Longest Palindromic Substring – LeetCode
Problem
Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring. Continue reading
Longest Substring Without Repeating Characters – LeetCode
Problem
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for “abcabcbb” is “abc”, which the length is 3. For “bbbbb” the longest substring is “b”, with the length of 1. Continue reading
Add Two Numbers – LeetCode
Problem
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list. Continue reading
Two Sum – LeetCode
Problem
Given an array of integers, find two numbers such that they add up to a specific target number.
The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2. Please note that your returned answers (both index1 and index2) are not zero-based. Continue reading