Skip to content

Instantly share code, notes, and snippets.

void dfs(char** grid, int rowMax, int colMax, int currentRow, int currentCol) {
if (currentRow >= rowMax || currentRow < 0 || currentCol >= colMax || currentCol < 0 || grid[currentRow][currentCol] != '1') return;
grid[currentRow][currentCol] = '0';
dfs(grid, rowMax, colMax, currentRow + 1, currentCol);
dfs(grid, rowMax, colMax, currentRow - 1, currentCol);
dfs(grid, rowMax, colMax, currentRow, currentCol + 1);
dfs(grid, rowMax, colMax, currentRow, currentCol - 1);
}
void dfs(char** grid, int rowMax, int colMax, int currentRow, int currentCol) {
if (currentRow >= rowMax || currentRow < 0 || currentCol >= colMax || currentCol < 0 || grid[currentRow][currentCol] != '1') return;
grid[currentRow][currentCol] = '0';
dfs(grid, rowMax, colMax, currentRow + 1, currentCol);
dfs(grid, rowMax, colMax, currentRow - 1, currentCol);
dfs(grid, rowMax, colMax, currentRow, currentCol + 1);
dfs(grid, rowMax, colMax, currentRow, currentCol - 1);
}
bool visit(int** rooms, int* roomsColSize, int roomNo, int* checkCountPtr, int* checkRooms, int roomSize) {
if (!checkRooms[roomNo]) {
checkRooms[roomNo] = 1;
*(checkCountPtr) += 1;
}
if (*checkCountPtr == roomSize)
return true;
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
int visit(struct TreeNode* node, int L, int R) {
if (!node) return 0;
int left = 0;
int right = 0;
left = visit(node->left, L, R);
right = visit(node->right, L, R);
if (node->val >= L && node->val <= R)
return left + right + node->val;
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
struct TreeNode* invertTree(struct TreeNode* root){
if (root) {
struct TreeNode* tmp = root->left;
root->left = invertTree(root->right);
root->right = invertTree(tmp);
}
return root;
}
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
void invert (struct TreeNode *node) {
@NigelJu
NigelJu / GA.py
Created April 30, 2019 14:36
GA.py
import random
import formatCSV
import financeToken
import StockNJ
import TradingRule
from IndicatorKdRuleInPassivation import *
import copy
DECIMAL_BIT_LEN = 4
ALPHA_BIT_LEN = 3