Algorithms_in_C 1.0.0
Set of algorithms implemented in C.
|
Implementation of the ZigZag Conversion Leetcode problem. More...
#include <assert.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Functions | |
char * | convert (char *in, uint16_t numRows) |
for assert for unsigned int with fixed size | |
static void | testZigZag (char *s, int numRows, char *expected) |
Self-test implementations. | |
static void | test () |
Self-test implementations. | |
int | main (void) |
Main function. | |
Implementation of the ZigZag Conversion Leetcode problem.
A decent solution to the ZigZag conversion problem. Take advantage of the fact that the maximum gap between the chars is 2 times the depth(the number of rows). The actual gap between the two first chars of a rows depends on the depth of the row. The gaps between successives chars on the same row is the complement of the first gap to the maximum gap.
char * convert | ( | char * | in, |
uint16_t | numRows | ||
) |
for assert for unsigned int with fixed size
for IO operations for malloc for string tools
Convert a string to the it's zigzag equivalent on a given number of rows.
in | the string in input. |
numRows | the desired number of rows. |
int main | ( | void | ) |
|
static |
Self-test implementations.
|
static |
Self-test implementations.