From 926d1cb0e5dda37d0af0535d3a9c3543f80638d2 Mon Sep 17 00:00:00 2001 From: iphkwan Date: Sat, 27 Sep 2014 10:44:00 +0800 Subject: [PATCH 1/6] Create Maximum_Product_Subarray.cc DP. In order to deal with the negatives, it needs to mark down the maximum(>0) and minimum result(<0) at the same time. --- Maximum_Product_Subarray.cc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Maximum_Product_Subarray.cc 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; + } +}; From 1c85298e03a027291aa0144a6ae7df56e421ce64 Mon Sep 17 00:00:00 2001 From: iphkwan Date: Sat, 27 Sep 2014 10:49:07 +0800 Subject: [PATCH 2/6] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 687cb6a..cb54ac9 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 Sep. 27th 2014. -> 151 / 151 +> 152 / 152 From d175c808a179e3ad8c4a70cf3afd1d6a2d037e17 Mon Sep 17 00:00:00 2001 From: iphkwan Date: Mon, 6 Oct 2014 16:25:23 +0800 Subject: [PATCH 3/6] Rename Recorder_List.cc to Reorder_List.cc Fix name's bug via @Jesse Wang --- Recorder_List.cc => Reorder_List.cc | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Recorder_List.cc => Reorder_List.cc (100%) diff --git a/Recorder_List.cc b/Reorder_List.cc similarity index 100% rename from Recorder_List.cc rename to Reorder_List.cc From 99c73479c06083747f7beaf716c5bf25cfb3636f Mon Sep 17 00:00:00 2001 From: iphkwan Date: Mon, 6 Oct 2014 16:25:54 +0800 Subject: [PATCH 4/6] Rename Maximun_Depth_of_Binary_Tree.cc to Maximum_Depth_of_Binary_Tree.cc Fix name's bug via @Jesse Wang --- ...n_Depth_of_Binary_Tree.cc => Maximum_Depth_of_Binary_Tree.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename Maximun_Depth_of_Binary_Tree.cc => Maximum_Depth_of_Binary_Tree.cc (95%) 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 +}; From d9bc0f123c7548020556f2b9399fcd0a0a38f033 Mon Sep 17 00:00:00 2001 From: iphkwan Date: Thu, 16 Oct 2014 23:59:43 +0800 Subject: [PATCH 5/6] Create Find_Minimum_in_Rotated_Sorted_Array.cc For the reason that it assumes no duplicate exists in the array...This problem seems more easier... --- Find_Minimum_in_Rotated_Sorted_Array.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Find_Minimum_in_Rotated_Sorted_Array.cc 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]; + } +}; From c53c1cef84ee2bb1a0f45e624ed4833bf60741a8 Mon Sep 17 00:00:00 2001 From: iphkwan Date: Fri, 17 Oct 2014 00:02:24 +0800 Subject: [PATCH 6/6] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cb54ac9..83f5b57 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,6 @@ leetcode Have fun! -Last updated at Sep. 27th 2014. +Last updated at Oct. 17th 2014. -> 152 / 152 +> 153 / 153