Skip to content

Commit 142a849

Browse files
committed
minor refactorings
1 parent 27a92f7 commit 142a849

File tree

5 files changed

+63
-6
lines changed

5 files changed

+63
-6
lines changed

src/main/java/com/ctci/treesandgraphs/FirstCommonAncestor.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
* tree. Avoid storing additional nodes in a data structure. Also, for this question, the tree node
66
* does NOT have access to its parent node. NOTE: This is not necessarily a binary search tree.
77
*
8+
* First Common Ancestor or the Least/Lowest Common Ancestor of two nodes is a node which is the
9+
* closest to both of the nodes.
10+
*
811
* @author rampatra
912
* @since 2019-02-24
1013
*/
@@ -18,7 +21,7 @@ public class FirstCommonAncestor {
1821
* - Returns null, if neither p nor q are in root's subtree.
1922
* - Else, returns the common ancestor of p and q.
2023
* <p>
21-
* See {@link com.rampatra.trees.LeastCommonAncestorInBT} for a simpler version.
24+
* See {@link com.rampatra.trees.LeastCommonAncestorInBT} for a better answer.
2225
*
2326
* @param root
2427
* @param a

src/main/java/com/leetcode/arrays/BuySellStocks.java

+21-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,27 @@
22

33
/**
44
* Level: Easy
5-
* Problem: https://leetcode.com/problems/best-time-to-buy-and-sell-stock/
5+
* Link: https://leetcode.com/problems/best-time-to-buy-and-sell-stock/
6+
* Description:
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 (i.e., buy one and sell one share of the stock),
10+
* design an algorithm to find the maximum profit.
11+
*
12+
* Note that you cannot sell a stock before you buy one.
13+
*
14+
* Example 1:
15+
*
16+
* Input: [7,1,5,3,6,4]
17+
* Output: 5
18+
* Explanation: Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5.
19+
* Not 7-1 = 6, as selling price needs to be larger than buying price.
20+
*
21+
* Example 2:
22+
*
23+
* Input: [7,6,4,3,1]
24+
* Output: 0
25+
* Explanation: In this case, no transaction is done, i.e. max profit = 0.
626
*
727
* @author rampatra
828
* @since 2019-04-23

src/main/java/com/leetcode/arrays/BuySellStocksII.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
/**
44
* Level: Easy
5-
* Problem Link: https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/
6-
* Problem Description:
5+
* Link: https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/
6+
* Description:
77
* Say you have an array for which the ith element is the price of a given stock on day i.
88
* <p>
99
* Design an algorithm to find the maximum profit. You may complete as many transactions as you

src/main/java/com/leetcode/arrays/MergeSortedArray.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,20 @@
44

55
/**
66
* Level: Easy
7-
* Problem Link: https://leetcode.com/problems/merge-sorted-array/
7+
* Link: https://leetcode.com/problems/merge-sorted-array/
8+
* Description:
9+
* Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.
10+
*
11+
* Note:
12+
* The number of elements initialized in nums1 and nums2 are m and n respectively.
13+
* You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold
14+
* additional elements from nums2.
15+
*
16+
* Example:
17+
* Input:
18+
* nums1 = [1,2,3,0,0,0], m = 3
19+
* nums2 = [2,5,6], n = 3
20+
* Output: [1,2,2,3,5,6]
821
*
922
* @author rampatra
1023
* @since 2019-04-26

src/main/java/com/leetcode/arrays/RotateArray.java

+22-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,28 @@
44

55
/**
66
* Level: Easy
7-
* Problem: https://leetcode.com/problems/rotate-array/
7+
* Link: https://leetcode.com/problems/rotate-array/
8+
* Description:
9+
* Given an array, rotate the array to the right by k steps, where k is non-negative.
10+
*
11+
* Example 1:
12+
* Input: [1,2,3,4,5,6,7] and k = 3
13+
* Output: [5,6,7,1,2,3,4]
14+
* Explanation:
15+
* rotate 1 steps to the right: [7,1,2,3,4,5,6]
16+
* rotate 2 steps to the right: [6,7,1,2,3,4,5]
17+
* rotate 3 steps to the right: [5,6,7,1,2,3,4]
18+
*
19+
* Example 2:
20+
* Input: [-1,-100,3,99] and k = 2
21+
* Output: [3,99,-1,-100]
22+
* Explanation:
23+
* rotate 1 steps to the right: [99,-1,-100,3]
24+
* rotate 2 steps to the right: [3,99,-1,-100]
25+
*
26+
* Note:
27+
* Try to come up as many solutions as you can, there are at least 3 different ways to solve this problem.
28+
* Could you do it in-place with O(1) extra space?
829
*
930
* @author rampatra
1031
* @since 2019-04-20

0 commit comments

Comments
 (0)