Create a map m to count the frequency of each implicit character c of the string s.
- Note: The character
cis 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 [email protected] | |
| 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()Kotlin
var transpose = { A: Array<IntArray> -> A[0].mapIndexed{ j, _ -> A.mapIndexed{ i, _ -> A[i][j] }.toIntArray() }.toTypedArray() }
Javascript
let transpose = A => A[0].map((_, j) => A.map((_, i) => A[i][j]));
| // | |
| // 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 { | |
| fun reverseList(head: ListNode?): ListNode? { | |
| fun go(node: ListNode? = head, last: ListNode? = null): ListNode? { | |
| var next = node?.next | |
| node?.next = last | |
| if (next == null) |
| // | |
| // 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; |
| # | |
| # 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. | |
| // | |
| class Solution { | |
| public: | |
| using fun = function<ListNode*(ListNode*, ListNode*)>; | |
| ListNode* reverseList(ListNode* head) { | |
| fun go = [&](auto node, auto last) { | |
| auto next = node->next; |
| fun permutations(A: IntArray): Array<IntArray> { | |
| var N = A.size | |
| var perms = mutableListOf<IntArray>() | |
| fun go(i: Int = 0) { | |
| if (i == N) { | |
| perms.add(A.copyOf()) | |
| return | |
| } | |
| for (k in i until N) { | |
| A[i] = A[k].also{ A[k] = A[i] } |
| let permutations = A => { | |
| let N = A.length; | |
| let perms = []; | |
| let go = (i = 0) => { | |
| if (i == N) { | |
| perms.push([...A]); | |
| return; | |
| } | |
| for (let k = i; k < N; ++k) { | |
| [A[i], A[k]] = [A[k], A[i]]; |