This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
double find_median_sorted_arrays(int *nums1, int nums1Size, int *nums2, int nums2Size) | |
{ | |
int nums3Size = nums1Size + nums2Size; | |
int nums3[nums3Size]; | |
int i = 0; | |
int j = 0; | |
while ((i != nums1Size) && (j != nums2Size)) | |
{ | |
if (nums1[i] <= nums2[j]) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ListNode *linked_addition(struct ListNode *l1, struct ListNode *l2) | |
{ | |
struct ListNode *l1Start = l1; | |
struct ListNode *l2Start = l2; | |
struct ListNode *lSum = (struct ListNode *)malloc(sizeof(struct ListNode)); | |
struct ListNode *lSumStart = lSum; | |
bool flag = true; | |
while (flag) | |
{ | |
lSum->val = l1->val + l2->val; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
char *longest_palindrome(char *s) | |
{ | |
int n = strlen(s); | |
if (n < 2) return s; // Every string of length 1 or 0 is a palindrome | |
bool p[n][n]; | |
memset(p, 0, sizeof(p)); | |
int start = 0; | |
int length = 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
char *zigzag_convert(char *s, int numRows) | |
{ | |
int numChars = strlen(s); | |
if (numRows == 1) return s; // Division by zero will occur in the next line otherwise. | |
int numColumns = numChars / (numRows + numRows - 2) * (numRows - 1) + numChars % (numRows + numRows - 2) / numRows + numChars % (numRows + numRows - 2) % numRows; | |
// Allocate space for the table. | |
char **table = malloc(numRows * sizeof(char *)); | |
for (int i = 0; i < numRows; i++) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int longest_substring(char* s) | |
{ | |
int string_length = strlen(s); | |
if (string_length == 0) | |
{ | |
return 0; | |
} | |
// form the string matrix | |
int string_matrix[string_length][string_length]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [L, U, P] = lu_pp(A) | |
% [L, U, P] = lu_pp(A) computes a unit lower triangular matrix L, | |
% an upper triangular matrix U, and a permutation matrix P such that | |
% P * A = L * U. | |
% The LU factorization is computed using partial pivoting. | |
% for the n x m matrix A, n == m | |
size_A = size(A); | |
if(size_A(1) ~= size_A(2)) | |
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [L, U, P] = lu_spp(A) | |
% [L, U, P] = lu_spp(A) computes a unit lower triangular matrix L, | |
% an upper triangular matrix U, and a permutation matrix P such that | |
% P * A = L * U. | |
% The LU factorization is computed using scaled partial pivoting. | |
% for the n x m matrix A, n == m | |
size_A = size(A); | |
if(size_A(1) ~= size_A(2)) | |
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function stock = get_yahoo_stockdata3(ticker,d1,d2,freq) | |
% Updated from v3 when in May 2017, yahoo went and changed how stock data | |
% was shown on web pages. | |
% | |
% INPUTS: | |
% | |
% ticker <-- Yahoo ticker symbol for desired security. This can be a char | |
% string for a single stock, or data can be retrieved for | |
% multiple stocks by using a cellstr array. | |
% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [S, count] = adaptive_simpson(f, a, b, epsilon, level, level_max) | |
% Evaluates the integral of f using Adaptive Simpson | |
% over [a, b] such that 1 / 15 * abs(S^(2) - S^(1)) < e. | |
count = 1; | |
level = level + 1; | |
h = b - a; | |
c = (a + b) / 2; | |
f_a = f(a); | |
f_c = f(c); | |
f_b = f(b); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [minx, minf, iter, funev] = bfgs(ffunc, gfunc, n, x0, epsfun, epsgrad, epsx, maxiter, maxfun) | |
% | |
% ******************* | |
% * MANDATORY INPUT * | |
% ******************* | |
% ffunc : A string indicating the function evaluation file. For example, | |
% if the file name is 'fMyFunction.m', then ffunc should be | |
% 'fMyFunction'. | |
% gfunc : A string indicating the gradient evaluation file. For example, | |
% if the file name is 'gadient.m', then gfunc should be |
OlderNewer