diff --git a/Find_Minimum_in_Rotated_Sorted_Array.cc b/Find_Minimum_in_Rotated_Sorted_Array.cc new file mode 100644 index 0000000..b2dff88 --- /dev/null +++ b/Find_Minimum_in_Rotated_Sorted_Array.cc @@ -0,0 +1,15 @@ +class Solution { +public: + int findMin(vector &num) { + int L = 0, R = num.size() - 1, M; + if (R < 0) return -1; + while (L < R) { + M = L + (R - L) / 2; + if (num[M] > num[R]) + L = M + 1; + else + R = M; + } + return num[L]; + } +}; diff --git a/Maximun_Depth_of_Binary_Tree.cc b/Maximum_Depth_of_Binary_Tree.cc similarity index 95% rename from Maximun_Depth_of_Binary_Tree.cc rename to Maximum_Depth_of_Binary_Tree.cc index 28c9737..70b3b60 100644 --- a/Maximun_Depth_of_Binary_Tree.cc +++ b/Maximum_Depth_of_Binary_Tree.cc @@ -17,4 +17,4 @@ class Solution { } return max(maxDepth(root->left), maxDepth(root->right)) + 1; } -}; \ No newline at end of file +}; diff --git a/Maximum_Product_Subarray.cc b/Maximum_Product_Subarray.cc new file mode 100644 index 0000000..f1aa2b9 --- /dev/null +++ b/Maximum_Product_Subarray.cc @@ -0,0 +1,17 @@ +class Solution { +public: + int maxProduct(int A[], int n) { + if (n <= 0) return 0; + int iMaxProductEndByPrePos = A[0], iMaxProductEndByCurrentPos; + int iMinProductEndByPrePos = A[0], iMinProductEndByCurrentPos; + int ret = A[0]; + for (int i = 1; i < n; i++) { + iMaxProductEndByCurrentPos = max(max(iMaxProductEndByPrePos * A[i], iMinProductEndByPrePos * A[i]), A[i]); + iMinProductEndByCurrentPos = min(min(iMaxProductEndByPrePos * A[i], iMinProductEndByPrePos * A[i]), A[i]); + ret = max(ret, iMaxProductEndByCurrentPos); + iMaxProductEndByPrePos = iMaxProductEndByCurrentPos; + iMinProductEndByPrePos = iMinProductEndByCurrentPos; + } + return ret; + } +}; diff --git a/README.md b/README.md index 687cb6a..83f5b57 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ leetcode ======== -No voice but big deal. +Have fun! -Last updated at Mar. 7th 2014. +Last updated at Oct. 17th 2014. -> 151 / 151 +> 153 / 153 diff --git a/Recorder_List.cc b/Reorder_List.cc similarity index 100% rename from Recorder_List.cc rename to Reorder_List.cc