Create a map m
to count the frequency of each implicit character c
of the string s
.
- Note: The character
c
is explicit in Rust and C++
Kotlin
var m = s.groupingBy{ it }.eachCount()
#!/bin/bash | |
git config --global user.name "claytonjwong" | |
git config --global user.email claytonjwong@gmail.com | |
git config --global alias.co checkout | |
git config --global alias.br branch | |
git config --global alias.ci commit | |
git config --global alias.st status | |
git config --global alias.au 'add . -u' | |
git config --global alias.di diff |
# https://en.wikipedia.org/wiki/Monty_Hall_problem | |
import random | |
N = int(1e5) | |
door = [1, 2, 3] | |
same = 0 | |
diff = 0 |
Create a map m
to count the frequency of each implicit character c
of the string s
.
c
is explicit in Rust and C++Kotlin
var m = s.groupingBy{ it }.eachCount()
// | |
// BUBBLE-SORT | |
// | |
// loop-invariant: | |
// | |
// the right-most i elements are the largest i elements in A[0:N), 0<=i<N | |
// sorted in ascending order | |
// | |
void bubble_sort1(vector<int>& A){ | |
bool swapped; |
/* | |
* Javascript version of C++ equal_range via lower_bound and upper_bound | |
* | |
* Gist: https://gist.github.com/claytonjwong/53bd1c1489b12eccad176addb8afd8e0 | |
*/ | |
let lowerBound = (A, T) => { | |
let N = A.length, | |
i = 0, | |
j = N; |
How to create and initialize 2D arrays of integers with:
int dp[M][N] = { [0 ... M-1] = { [0 ... N-1] = X } };
template< typename T > | |
class Solution | |
{ | |
using Vector = vector< T >; | |
using Iter = typename Vector::iterator; | |
Vector go( Vector&& A ) | |
{ | |
auto N{ A.size() }; | |
if( N < 2 ) return A; |
// | |
// Recursively change each node of the linked list such that next | |
// is the last node seen during a linear scan of the linked list. | |
// | |
class Solution { | |
public: | |
using fun = function<ListNode*(ListNode*, ListNode*)>; | |
ListNode* reverseList(ListNode* head) { | |
fun go = [&](auto node, auto last) { | |
auto next = node->next; |
# | |
# Recursively change each node of the linked list such that next | |
# is the last node seen during a linear scan of the linked list. | |
# | |
class Solution: | |
def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]: | |
def go(node = head, last = None): | |
next = node.next | |
node.next = last | |
if not next: |
// | |
// Recursively change each node of the linked list such that next | |
// is the last node seen during a linear scan of the linked list. | |
// | |
let reverseList = head => { | |
let go = (node = head, last = null) => { | |
let next = node.next; | |
node.next = last; | |
if (!next) | |
return node; |