Tested Solution Locally, Works, Doesn't work in oj


  • 0
    B
    class Solution {
    public:
        void rotate(int nums[], int n, int k) {
            int solution[n];
            for(int i = 0; i < n; i++){
                if(i < k){
                    solution[i] = nums[i + (n - k)];
                } else {
                    solution[i] = nums[i - k];
                }
            }
        }
    };
    

    I tested this solution on the test case the leetcode is saying I'm getting wrong, and it is getting it right. This is consistent with my very slow and methodical read through of the logic, which appears to be correct.


  • 0
    R

    You have to modify nums[] directly, not create another list.

    Your variable "solution[]" might be correct, but the site checks "nums[]" to see if it is correct.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.