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
from functools import wraps # This convenience func preserves name and docstring | |
class A: | |
pass | |
def add_method(cls): | |
def decorator(func): | |
@wraps(func) | |
def wrapper(self, *args, **kwargs): | |
return func(*args, **kwargs) |
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
# colors! | |
green="\[\033[0;32m\]" | |
blue="\[\033[0;34m\]" | |
purple="\[\033[0;35m\]" | |
yellow="\[\033[0;33m\]" | |
red="\[\033[0;31m\]" | |
reset="\[\033[0m\]" | |
export PS1="| $green\w $yellow@ $green\h $yellow(\u)$reset \n| $ " | |
export PS2="| => " |
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
bool remove(T d) { | |
if (!contains(d)) | |
return false; | |
removeHelper(root_, d); | |
return true; | |
} | |
TreeNode<T>* removeHelper(TreeNode<T> *n, T d) { | |
if (d < n->data_) { | |
n->left_ = removeHelper(n->left_, d); |
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
static String Decoding(String[] encodings, String encodedstring) { | |
HashMap<String, String> map = new HashMap<>(); // <code, char> | |
for (String s : encodings) { | |
String[] splited = s.split("\\t"); | |
if (splited[0].equals("[newline]")) | |
splited[0] = "\n"; | |
map.put(splited[1], splited[0]); | |
} | |
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
import java.io.*; | |
import java.util.*; | |
public class Solution { | |
private static boolean isAnagram(String a, String b) { | |
char[] a_arr = a.toCharArray(); | |
char[] b_arr = b.toCharArray(); | |
Arrays.sort(a_arr); | |
Arrays.sort(b_arr); | |
String sorted_a = new String(a_arr); |
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
static String firstRepeatedWord(String s) { | |
HashSet<String> hashset = new HashSet<>(); | |
String[] splited = s.split("\\s+"); | |
for (String word : splited) { | |
word = word.trim().replaceAll("\\W", ""); | |
if (hashset.contains(word)) { | |
return word; | |
} else { | |
hashset.add(word); | |
} |
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
/* | |
* Complete the function below. | |
*/ | |
static private class TreeNode { | |
public int val; | |
public TreeNode left; | |
public TreeNode right; | |
public TreeNode(int n){ |
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 <iostream> | |
using namespace std; | |
int reverseAsHex(int n) { | |
int mask = 0xF; // or 15 | |
int answer = 0; | |
while (n != 0) { | |
answer = (answer << 4) | (n & mask); | |
n >>= 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 <iostream> | |
#include <vector> | |
#include <climits> | |
using namespace std; | |
class Max2{ | |
public: | |
Max2() : largest(INT_MIN), nextlargest(INT_MIN), lindex(-1), nlindex(-1) { }; | |
friend ostream& operator<<(ostream& os, Max2 m); | |
void insert(int n, int nindex); |
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
var callback = function(x) { coordinates = x; } | |
navigator.geolocation.getCurrentPosition(callback); | |
console.log(coordinates); |
NewerOlder