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 json | |
# Example 1: Python JSON to dict | |
print ("Example #1: Python JSON to dict") | |
person = '{"name": "Bob", "languages": ["English", "Fench"]}' | |
person_dict = json.loads(person) |
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.*; | |
/* | |
* THIS FILE IS DEVELOPED BY YIFAN LI | |
* Copyright (c) 2017 Yifan Li | |
*/ | |
class Board{ |
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 <string> | |
#include <stack> | |
using namespace std; | |
struct TreeNode { | |
int val; | |
vector<TreeNode*> children = {}; | |
TreeNode(int _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
public class SortDeckOfCard { | |
static class Card { | |
int suite; | |
int rank; | |
public Card(int suite, int rank) { | |
this.suite = suite; | |
this.rank = rank; | |
} | |
} |
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
/* | |
* TimeTravelingHashTable | |
* insert(key, value, timestamp) | |
* get(key, timestamp) | |
* get(key) // returns value associated with key at latest time | |
* | |
* insert("k1", "v1", 10) | |
* get("k1") // returns "v1" | |
* get("k1", 11) // returns "v1" | |
* insert("k1", "v2", 20) |
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
// void index(Document document) | |
// List<Document> search(String query) | |
import java.util.*; | |
class Document { | |
String id; | |
String content; | |
public Document(String id, String content) { | |
this.id = id; | |
this.content = content; |
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 class MedianOccurence { | |
static class Ele {. From 1point 3acres bbs | |
char c ; | |
int times; | |
public Ele(char c, int t) { | |
this.c = c; | |
times = t; | |
} | |
} |
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
void read(MyDB_Page &page){ | |
pair<MyDB_TablePtr,size_t> key = make_pair(page.whichTable, page.offset); | |
if(pos.find(key) != pos.end()){ //this page is in buffer | |
recent.erase(pos[key]); //this page exists, so no need to check whether the page exists in buffer | |
} | |
else{ // this page isn't in buffer | |
if( recent.size() >= numPages ){ //check whether buffer is full | |
evict(); |