problem 27

Signed-off-by: Krishna Vedala <7001608+kvedala@users.noreply.github.com>
This commit is contained in:
Krishna Vedala 2020-10-31 06:28:14 -04:00
parent 5ff7e5fb62
commit f8cdb019a4
No known key found for this signature in database
GPG Key ID: BA19ACF8FC8792F7

View File

@ -1,3 +1,23 @@
/**
* \file
* \brief [3. Longest
* substring](https://leetcode.com/problems/longest-substring-without-repeating-characters/)
* brute force solution
* \details Given a string `s`, find the length of the longest substring without
* repeating characters.
*/
#include <assert.h>
#include <stdio.h>
/**
* @brief Remove a value from a given array.
*
* @param [in,out] nums array of numbers that gets modified in place
* @param numsSize length of input array
* @param val value to remove from the array
* @return length of the new array
*/
int removeElement(int *nums, int numsSize, int val)
{
int i, start = 0;
@ -8,3 +28,24 @@ int removeElement(int *nums, int numsSize, int val)
}
return start;
}
/**
* @brief Main function
* @return 0
*/
int main()
{
int nums1[] = {3, 2, 2, 3}, l1 = 4;
int out1 = removeElement(nums1, l1, 3);
assert(out1 == 2);
for (int i = 0; i < out1; i++) printf("%d ", nums1[i]);
putchar('\n');
int nums2[] = {0, 1, 2, 2, 3, 0, 4, 2}, l2 = 8;
int out2 = removeElement(nums2, l2, 2);
assert(out2 == 5);
for (int i = 0; i < out2; i++) printf("%d ", nums2[i]);
putchar('\n');
return 0;
}