From 869f7ed1735df0787a0da3e39bf340922089bedc Mon Sep 17 00:00:00 2001 From: chayan das <110921638+Chayandas07@users.noreply.github.com> Date: Sun, 2 Feb 2025 23:02:18 +0530 Subject: [PATCH] Create 1752. Check if Array Is Sorted and Rotated --- 1752. Check if Array Is Sorted and Rotated | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 1752. Check if Array Is Sorted and Rotated diff --git a/1752. Check if Array Is Sorted and Rotated b/1752. Check if Array Is Sorted and Rotated new file mode 100644 index 0000000..6fae8eb --- /dev/null +++ b/1752. Check if Array Is Sorted and Rotated @@ -0,0 +1,15 @@ +class Solution { +public: + bool check(vector& nums) { + int n = nums.size(); + int count = 0; + + for (int i = 0; i < n; i++) { + if (nums[i] > nums[(i + 1) % n]) { + count++; + } + } + + return count <= 1; + } +};