1234567891011121314 |
- /* Create a function that goes through the array, incrementing
- * (+1) for each odd number and decrementing (-1)
- * for each even number.
- * ex. transform([1, 2, 3, 4, 5]) ➞ [2, 1, 4, 3, 6]
- */
- std::vector<int> transform(std::vector<int> arr) {
- for(int i = 0;i<arr.size();i++){
- // evaluate if even, -1 if even
- if(arr[i]%2 == 0){arr[i]-=1;}
- // evaluate if odd, +1 if odd
- else arr[i]+=1;
- }
- return arr;
- }
|