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
using System.IO; | |
using System; | |
class Solution { | |
// Complete the hourglassSum function below. | |
static int hourglassSum(int[][] arr) { | |
int[] sum = new int[16]; | |
int k = 0; | |
for (int i = 0; i <= 3; 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
public function format_phone_number($S) { | |
$S = str_replace(' ', '', $S); | |
$S = str_replace('-', '', $S); | |
$len = strlen($S); | |
$num_groups = floor($len / 3); | |
$remain = $len % 3; | |
if ($num_groups >= 1 && $remain == 1) { | |
$num_groups -= 1; | |
$remain += 3; //4 |
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
#include "pch.h" | |
#include <iostream> | |
#include <algorithm> | |
#include <string> | |
#include <vector> | |
#include <time.h> | |
using namespace std; | |
int get_max_profit(vector<int> prices); |
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
<?php | |
//this is to get the max gap in an array supposing gap can only be a later number minus a former number | |
$stock_prices_yesterday = [25, 7, 5, 8, 11, 9]; | |
$m_profit = GetMaxProfit($stock_prices_yesterday); | |
# returns 6 (buying for $5 and selling for $11) | |
print "1st:the most profit should be 6: {$m_profit}"; | |
$stock_prices_yesterday = [10, 7, 11, 5, 8, 9]; | |
$m_profit = GetMaxProfit($stock_prices_yesterday); |
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
<?php | |
// you can write to stdout for debugging purposes, e.g. | |
// print "this is a debug message\n"; | |
function solution($A) { | |
// write your code in PHP7.0 | |
$arr_checker = range(1, 100000); | |
$A = array_unique($A, SORT_NUMERIC ); | |
sort($A); |
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
/** | |
* Convert a value to studly caps case. | |
* | |
* @param string $value | |
* | |
* @return string | |
*/ | |
public function studly(string $value): string | |
{ | |
return \str_replace(' ', '', \ucwords(\str_replace(['-', '_'], ' ', $value))); |
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
/** | |
* Convert a string to snake case. | |
* | |
* @param string $value | |
* @param string $delimiter Default to underscore | |
* | |
* @return string | |
*/ | |
public function snake(string $value, ?string $delimiter = null): string | |
{ |
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
<?php | |
namespace App\Debugger; | |
/** | |
* usage example: $log = new MyLogger(); $logger->log($logger::ARGTRACE_NONE . $logger::BACKTRACE_NONE . $logger::SELF_ARGUMENTS_LOW, .......) | |
*/ | |
//for Symfony project, this is put under src/Debugger/ folder | |
//for Lumen and Laravel, this is put under app/Debugger/ folder | |
//create logs directory under PROJECT_HOME |