Skip to content

Commit ad62b9d

Browse files
committed
add the problem content into source file
1 parent 512b39d commit ad62b9d

File tree

153 files changed

+2449
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

153 files changed

+2449
-1
lines changed

src/3Sum/3Sum.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@
22
// Author : Hao Chen
33
// Date : 2014-07-22
44

5+
/**********************************************************************************
6+
*
7+
* 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.
8+
*
9+
* Note:
10+
*
11+
* Elements in a triplet (a,b,c) must be in non-descending order. (ie, a ≤ b ≤ c)
12+
* The solution set must not contain duplicate triplets.
13+
*
14+
* For example, given array S = {-1 0 1 2 -1 -4},
15+
*
16+
* A solution set is:
17+
* (-1, 0, 1)
18+
* (-1, -1, 2)
19+
*
20+
*
21+
**********************************************************************************/
22+
523
#include <stdio.h>
624
#include <iostream>
725
#include <vector>

src/3SumClosest/3SumClosest.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22
// Author : Hao Chen
33
// Date : 2014-07-03
44

5+
/**********************************************************************************
6+
*
7+
* 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.
8+
*
9+
* For example, given array S = {-1 2 1 -4}, and target = 1.
10+
*
11+
* The sum that is closest to the target is 2. (-1 + 2 + 1 = 2).
12+
*
13+
*
14+
**********************************************************************************/
15+
516
#include <stdio.h>
617
#include <stdlib.h>
718
#include <iostream>

src/4Sum/4Sum.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22
// Author : Hao Chen
33
// Date : 2014-07-03
44

5+
/**********************************************************************************
6+
*
7+
* Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.
8+
*
9+
* Note:
10+
*
11+
* Elements in a quadruplet (a,b,c,d) must be in non-descending order. (ie, a ≤ b ≤ c ≤ d)
12+
* The solution set must not contain duplicate quadruplets.
13+
*
14+
* For example, given array S = {1 0 -1 0 -2 2}, and target = 0.
15+
*
16+
* A solution set is:
17+
* (-1, 0, 0, 1)
18+
* (-2, -1, 1, 2)
19+
* (-2, 0, 0, 2)
20+
*
21+
*
22+
**********************************************************************************/
23+
524
#include <iostream>
625
#include <vector>
726
#include <algorithm>

src/LRUCache/LRUCache.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
// Author : Hao Chen
33
// Date : 2014-10-12
44

5+
/**********************************************************************************
6+
*
7+
* Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set.
8+
*
9+
* get(key) - Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1.
10+
* set(key, value) - Set or insert the value if the key is not already present. When the cache reached its capacity, it should invalidate the least recently used item before inserting a new item.
11+
*
12+
*
13+
**********************************************************************************/
14+
515
#include <stdlib.h>
616
#include <time.h>
717
#include <iostream>

src/addBinary/addBinary.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22
// Author : Hao Chen
33
// Date : 2014-07-05
44

5+
/**********************************************************************************
6+
*
7+
* Given two binary strings, return their sum (also a binary string).
8+
*
9+
* For example,
10+
* a = "11"
11+
* b = "1"
12+
* Return "100".
13+
*
14+
*
15+
**********************************************************************************/
16+
517
#include <iostream>
618
#include <string>
719
using namespace std;

src/addTwoNumbers/addTwoNumbers.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22
// Author : Hao Chen
33
// Date : 2014-06-18
44

5+
/**********************************************************************************
6+
*
7+
* 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.
8+
*
9+
* Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
10+
* Output: 7 -> 0 -> 8
11+
*
12+
**********************************************************************************/
13+
514
/**
615
* Definition for singly-linked list.
716
* struct ListNode {

src/anagrams/anagrams.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
// Author : Hao Chen
33
// Date : 2014-07-18
44

5+
/**********************************************************************************
6+
*
7+
* Given an array of strings, return all groups of strings that are anagrams.
8+
*
9+
* Note: All inputs will be in lower-case.
10+
*
11+
**********************************************************************************/
12+
513
class Solution {
614
public:
715
vector<string> anagrams(vector<string> &strs) {

src/balancedBinaryTree/balancedBinaryTree.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22
// Author : Hao Chen
33
// Date : 2014-06-28
44

5+
/**********************************************************************************
6+
*
7+
* Given a binary tree, determine if it is height-balanced.
8+
*
9+
* For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1.
10+
*
11+
*
12+
**********************************************************************************/
13+
514
/**
615
* Definition for binary tree
716
* struct TreeNode {

src/bestTimeToBuyAndSellStock/bestTimeToBuyAndSellStock.II.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
// Author : Hao Chen
33
// Date : 2014-06-18
44

5+
/**********************************************************************************
6+
*
7+
* Say you have an array for which the ith element is the price of a given stock on day i.
8+
*
9+
* Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one and sell one share of the stock multiple times). However, you may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again).
10+
*
11+
**********************************************************************************/
12+
513
class Solution {
614
public:
715
int maxProfit(vector<int> &prices) {

src/bestTimeToBuyAndSellStock/bestTimeToBuyAndSellStock.III.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22
// Author : Hao Chen
33
// Date : 2014-08-22
44

5+
/**********************************************************************************
6+
*
7+
* Say you have an array for which the ith element is the price of a given stock on day i.
8+
*
9+
* Design an algorithm to find the maximum profit. You may complete at most two transactions.
10+
*
11+
* Note:
12+
* You may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again).
13+
*
14+
**********************************************************************************/
15+
516

617
class Solution {
718
public:

src/bestTimeToBuyAndSellStock/bestTimeToBuyAndSellStock.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
// Author : Hao Chen
33
// Date : 2014-06-18
44

5+
/**********************************************************************************
6+
*
7+
* Say you have an array for which the ith element is the price of a given stock on day i.
8+
*
9+
* If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), design an algorithm to find the maximum profit.
10+
*
11+
**********************************************************************************/
12+
513
class Solution {
614
public:
715
int maxProfit(vector<int> &prices) {

src/binaryTreeInorderTraversal/binaryTreeInorderTraversal.cpp

+38
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,44 @@
22
// Author : Hao Chen
33
// Date : 2014-06-27
44

5+
/**********************************************************************************
6+
*
7+
* Given a binary tree, return the inorder traversal of its nodes' values.
8+
*
9+
* For example:
10+
* Given binary tree {1,#,2,3},
11+
*
12+
* 1
13+
* \
14+
* 2
15+
* /
16+
* 3
17+
*
18+
* return [1,3,2].
19+
*
20+
* Note: Recursive solution is trivial, could you do it iteratively?
21+
*
22+
* confused what "{1,#,2,3}" means? > read more on how binary tree is serialized on OJ.
23+
*
24+
* OJ's Binary Tree Serialization:
25+
*
26+
* The serialization of a binary tree follows a level order traversal, where '#' signifies a path terminator where no node exists below.
27+
*
28+
* Here's an example:
29+
*
30+
* 1
31+
* / \
32+
* 2 3
33+
* /
34+
* 4
35+
* \
36+
* 5
37+
*
38+
* The above binary tree is serialized as "{1,2,3,#,#,4,#,#,5}".
39+
*
40+
*
41+
**********************************************************************************/
42+
543
/**
644
* Definition for binary tree
745
* struct TreeNode {

src/binaryTreeLevelOrderTraversal/binaryTreeLevelOrderTraversal.II.cpp

+42
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,48 @@
22
// Author : Hao Chen
33
// Date : 2014-06-27
44

5+
/**********************************************************************************
6+
*
7+
* Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).
8+
*
9+
* For example:
10+
* Given binary tree {3,9,20,#,#,15,7},
11+
*
12+
* 3
13+
* / \
14+
* 9 20
15+
* / \
16+
* 15 7
17+
*
18+
* return its bottom-up level order traversal as:
19+
*
20+
* [
21+
* [15,7],
22+
* [9,20],
23+
* [3]
24+
* ]
25+
*
26+
* confused what "{1,#,2,3}" means? > read more on how binary tree is serialized on OJ.
27+
*
28+
* OJ's Binary Tree Serialization:
29+
*
30+
* The serialization of a binary tree follows a level order traversal, where '#' signifies a path terminator where no node exists below.
31+
*
32+
* Here's an example:
33+
*
34+
* 1
35+
* / \
36+
* 2 3
37+
* /
38+
* 4
39+
* \
40+
* 5
41+
*
42+
* The above binary tree is serialized as "{1,2,3,#,#,4,#,#,5}".
43+
*
44+
*
45+
**********************************************************************************/
46+
547
/**
648
* Definition for binary tree
749
* struct TreeNode {

src/binaryTreeLevelOrderTraversal/binaryTreeLevelOrderTraversal.cpp

+42
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,48 @@
22
// Author : Hao Chen
33
// Date : 2014-07-17
44

5+
/**********************************************************************************
6+
*
7+
* Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).
8+
*
9+
* For example:
10+
* Given binary tree {3,9,20,#,#,15,7},
11+
*
12+
* 3
13+
* / \
14+
* 9 20
15+
* / \
16+
* 15 7
17+
*
18+
* return its level order traversal as:
19+
*
20+
* [
21+
* [3],
22+
* [9,20],
23+
* [15,7]
24+
* ]
25+
*
26+
* confused what "{1,#,2,3}" means? > read more on how binary tree is serialized on OJ.
27+
*
28+
* OJ's Binary Tree Serialization:
29+
*
30+
* The serialization of a binary tree follows a level order traversal, where '#' signifies a path terminator where no node exists below.
31+
*
32+
* Here's an example:
33+
*
34+
* 1
35+
* / \
36+
* 2 3
37+
* /
38+
* 4
39+
* \
40+
* 5
41+
*
42+
* The above binary tree is serialized as "{1,2,3,#,#,4,#,#,5}".
43+
*
44+
*
45+
**********************************************************************************/
46+
547
#include <stdio.h>
648
#include <stdlib.h>
749
#include <time.h>

src/binaryTreeMaximumPathSum/binaryTreeMaximumPathSum.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@
22
// Author : Hao Chen
33
// Date : 2014-10-10
44

5+
/**********************************************************************************
6+
*
7+
* Given a binary tree, find the maximum path sum.
8+
*
9+
* The path may start and end at any node in the tree.
10+
*
11+
* For example:
12+
* Given the below binary tree,
13+
*
14+
* 1
15+
* / \
16+
* 2 3
17+
*
18+
* Return 6.
19+
*
20+
*
21+
**********************************************************************************/
22+
523
#include <iostream>
624
#include <algorithm>
725
using namespace std;

src/binaryTreePostorderTraversal/binaryTreePostorderTraversal.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22
// Author : Hao Chen
33
// Date : 2014-07-21
44

5+
/**********************************************************************************
6+
*
7+
* Given a binary tree, return the postorder traversal of its nodes' values.
8+
*
9+
* For example:
10+
* Given binary tree {1,#,2,3},
11+
*
12+
* 1
13+
* \
14+
* 2
15+
* /
16+
* 3
17+
*
18+
* return [3,2,1].
19+
*
20+
* Note: Recursive solution is trivial, could you do it iteratively?
21+
*
22+
**********************************************************************************/
23+
524
#include <stdio.h>
625
#include <stdlib.h>
726
#include <time.h>

0 commit comments

Comments
 (0)