Procházet zdrojové kódy

April Day 4 done

master
Lachlan Jacob před 5 roky
rodič
revize
967ee005d8
4 změnil soubory, kde provedl 52 přidání a 1 odebrání
  1. 35
    0
      283/main.c
  2. 12
    0
      283/problem.txt
  3. 5
    0
      283/run.sh
  4. 0
    1
      README.md

+ 35
- 0
283/main.c Zobrazit soubor

@@ -0,0 +1,35 @@
#include <stdio.h>

void moveZeroes(int*, int);
void moveZeroes(int* nums, int numsSize){
int numZeroes = 0;
for (int i = 0; i < numsSize; i++) {
if (nums[i] == 0) {
numZeroes++;
} else {
nums[i - numZeroes] = nums[i];
}
}

for (int i = 0; i < numZeroes; i++) {
nums[numsSize - 1 - i] = 0;
}
}

int main() {
int nums[5] = {0, 1, 0, 3, 12};
int expectedResult[5] = {1, 3, 12, 0, 0};
printf("Expected: ");
for (int i = 0; i < 5; i++) {
printf("%d ", expectedResult[i]);
}
printf("\n");

moveZeroes(nums, 5);

printf("Got: ");
for (int i = 0; i < 5; i++) {
printf("%d ", nums[i]);
}
printf("\n");
}

+ 12
- 0
283/problem.txt Zobrazit soubor

@@ -0,0 +1,12 @@
Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.

Example:

Input: [0,1,0,3,12]
Output: [1,3,12,0,0]

Note:

You must do this in-place without making a copy of the array.
Minimize the total number of operations.


+ 5
- 0
283/run.sh Zobrazit soubor

@@ -0,0 +1,5 @@
#!/bin/bash

gcc -o main main.c
./main
rm main

+ 0
- 1
README.md Zobrazit soubor

@@ -19,7 +19,6 @@ To run all problems you will need installed on your system:
- python3 (preferably >3.8)
- rustc
- gcc
- SQlite

Then you can see all the problems go through an example case with:


Načítá se…
Zrušit
Uložit