below is my code, It runs well in CodeBlocks ,but in OJ Always shows " Runtime Error " Who can help me ?why?

```
class Solution
{
public:
void rotate(int nums[], int n, int k)
{
k = k % n;
if(k == 0 || n == 1) return;
int tem[n];
int j = 0;
for(int i = n - k; i < n; ++i,++j)
tem[j] = nums[i];
for(int i = 0; i <= k ; i++,j++)
tem[j] = nums[i];
for(int i = 0; i < n; ++i)
nums[i] = tem[i];
}
};
```