Posts

Showing posts from May, 2017

Problem 1: TwoSum

Image
The problem is as follows: Given an array of integers, return  indices  of the two numbers such that they add up to a specific target. You may assume that each input would have  exactly  one solution, and you may not use the  same  element twice. Example: Given nums = [2, 7, 11, 15], target = 9, Because nums[ 0 ] + nums[ 1 ] = 2 + 7 = 9, return [ 0 , 1 ]. There are several ways to achieve this. The straightforward solution is to use brute-force search. 1. Brute-Force Search C++: To declare and create an object of a class, either following way is ok: (1). Solution a; Num_output = a.twoSum(...) (2). Solution *a = new Solution(); Num_output = a->twoSum(...) The vector in C++ is written as {x1,x2,...} . Indexing an element: nums.at(i) . Get vector size: nums.size() . Note: in C++, the int main() is a must. For main function it cannot be changed to other types except int. Java: Use Solution a = new Solution() to create an object...

Start My LeetCode Journey Here

This blog is used to record my LeetCode experiences. I'll start from the Easy problems and hope I can solve all problems on LeetCode. For each problem, I will use 3 programming languages: C++/Java/Python and I will try every possible algorithms I have as well as other solutions proposed by other great people on LeetCode. This blog is for my own recordings. However if other people find it useful, it would be really great. I hope I can achieve this accomplishment ASAP and I believe such coding experiences will help me during the code interview with companies like Google, Apple or Facebook. Let's get started!😎