#include <seth>
2 subscribers
41 photos
9 videos
6 files
213 links
🔙 GET AWAY
Download Telegram
#include <seth>
https://leetcode.com/problems/maximum-nesting-depth-of-two-valid-parentheses-strings/ static int a[10000]; int* maxDepthAfterSplit(char* seq, int* returnSize) { *returnSize = 0; for (int i = 0, d = 0; seq[i]; ++i) a[(*returnSize)++] = (d = ~d) + seq[i]…
https://leetcode.com/problems/generate-parentheses/

static int F[] = {1, 2, 5, 14, 42, 132, 429, 1430};
char** generateParenthesis(int n, int* returnSize) {
*returnSize = F[n - 1];

int string_size = n * 2 + 1;
int vector_size = F[n - 1] * sizeof(char *);
char *arena = malloc(vector_size + F[n - 1] * string_size);
char **vector = (char **)arena;
for (int i = 0; i < F[n - 1]; ++i) {
vector[i] = arena + vector_size + (string_size * i);
vector[i][string_size - 1] = 0;
}

int source = (1 << n) - 1;
int target = 0;
for (int i = 0; i < n; ++i) target = (target << 2) | 1;
for (int i = 0; ; ++i) {
for (int j = 0; j < 2 * n; ++j)
vector[i][j] = ((source >> (2 * n - 1 - j)) & 1) ? ')' : '(';

if (source == target)
break;

int open_count = 0, close_count = 0;
for (int i = 0; i < 2 * n; ++i) {
if ((source >> i) & 1) ++close_count;
else {
++open_count;
if (close_count > open_count) {
source |= (1 << i);
source &= ~((1 << i) - 1);
source |= ((1 << (close_count - 1)) - 1);
break;
}
}
}
}

return vector;
}


#leetcode #c
Forwarded from 🍌 C++ Feed
Forwarded from opennet.ru
Создана среда, позволяющая собирать С++ приложения для Windows, Linux, macOS в браузере

Группа энтузиастов собрала SDK Xenolith, позволяющий собирать полноценные настольные приложения прямо в браузере. Система позволяет кросс-компилировать графические приложения с любой из поддерживаемых систем на любую другую. Одной из поддерживаемых систем является WebAssembly, потому приложения можно собирать для браузера, и собирать в браузере для любой другой платформы. Исходный код проекта написан на C++ и доступен под лицензией MIT.

Подробнее:
https://opennet.ru/66384/
https://opennet.me/66384/
#include <seth>
https://leetcode.com/problems/find-the-longest-semi-repetitive-substring/ int longestSemiRepetitiveSubstring(char* s) { int a = 0; for (int l = 0, r = 0, w = 0; s[r]; ++r) { w += r > 0 && s[r - 1] == s[r]; while (w > 1) w -= s[l + 1] == s[l++];…
https://leetcode.com/problems/valid-parenthesis-string/

bool checkValidString(char* s) {
int min = 0, max = 0;
for (int i = 0; s[i]; ++i) {
int x = (s[i] == '(') - (s[i] == ')');
min += x;
max += x;

int y = s[i] == '*';
min -= y;
max += y;
if (max < 0) return false;
if (min < 0) min = 0;
}
return !min;
}


#leetcode #c
Forwarded from Andrey Belyaev
Forwarded from eternal classic