From a2401b35449d05abddf96f4ffb790a23c860b2ae Mon Sep 17 00:00:00 2001 From: Pooja Date: Tue, 8 Dec 2020 20:51:10 +0530 Subject: [PATCH] Create week1_pooja --- Week1/Monotonic Array/week1_pooja | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Week1/Monotonic Array/week1_pooja diff --git a/Week1/Monotonic Array/week1_pooja b/Week1/Monotonic Array/week1_pooja new file mode 100644 index 0000000..bbfeaea --- /dev/null +++ b/Week1/Monotonic Array/week1_pooja @@ -0,0 +1,23 @@ +class Solution { +public: + bool isMonotonic(vector& A) { + + return A[0] <= A[A.size() - 1] ? isIncreasing(A) : isDecreasing(A); + } + + bool isIncreasing(vector& A){ + + for(int i = 1; i < A.size(); i++) + if(A[i - 1] > A[i]) + return false; + return true; + } + + bool isDecreasing(vector& A){ + + for(int i = 1; i < A.size(); i++) + if(A[i - 1] < A[i]) + return false; + return true; + } +};