Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <unordered_map>
- using namespace std;
- class Solution {
- public:
- bool checkPossibility(vector<int>& nums) {
- int counter = 0;
- int size = nums.size() - 1;
- auto sorted_nums = nums;
- sort(nums.begin(), nums.end());
- for(int i = 0; i < size; i++) {
- if (nums[i] > sorted_nums[i]) {
- counter++;
- }
- }
- return counter <= 2;
- }
- };
- void call_sol(vector<int> nums) {
- Solution s;
- for ( auto i: nums)
- cout << i << ", ";
- cout << ": " << s.checkPossibility(nums) << endl;
- }
- int main() {
- call_sol(vector<int> {4,2,3});
- call_sol(vector<int> {4,2,1});
- call_sol(vector<int> {2,3,3,2,4});
- call_sol(vector<int> {3, 4, 2 ,3});
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement