aboutsummaryrefslogtreecommitdiffstats
path: root/leetcode/3379/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'leetcode/3379/main.c')
-rw-r--r--leetcode/3379/main.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/leetcode/3379/main.c b/leetcode/3379/main.c
new file mode 100644
index 0000000..ef62b87
--- /dev/null
+++ b/leetcode/3379/main.c
@@ -0,0 +1,25 @@
+#include <stdlib.h>
+#include <math.h>
+
+
+/**
+ * Note: The returned array must be malloced, assume caller calls free().
+ */
+int* constructTransformedArray(int* nums, int numsSize, int* returnSize) {
+ int* result = malloc(sizeof(int) * numsSize);
+ *returnSize = numsSize;
+
+ for(int i = 0; i < numsSize; i++) {
+ if (nums[i] == 0) {
+ result[i] = 0;
+ } else {
+ int j = (i + nums[i]) % numsSize;
+ if (j < 0) {
+ j += numsSize;
+ }
+ result[i] = nums[j];
+ }
+ }
+
+ return result;
+}