Skip to content

Instantly share code, notes, and snippets.

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)
import java.io.*;
import java.util.*;
/*
* THIS FILE IS DEVELOPED BY YIFAN LI
* Copyright (c) 2017 Yifan Li
*/
class Board{
@bookybooky
bookybooky / deserialize_serialize_n_ary.cpp
Created March 18, 2017 05:28
tree是n-ary tree,板上面經題.
#include <iostream>
#include <vector>
#include <string>
#include <stack>
using namespace std;
struct TreeNode {
int val;
vector<TreeNode*> children = {};
TreeNode(int _val) {
@bookybooky
bookybooky / SortDeckOfCard.java
Created March 18, 2017 05:20
sort a deck of card 桶排序
public class SortDeckOfCard {
static class Card {
int suite;
int rank;
public Card(int suite, int rank) {
this.suite = suite;
this.rank = rank;
}
}
@bookybooky
bookybooky / TimeTravelingHashTable.java
Created March 18, 2017 05:10
Implement TimeTravelingHashTable的get和insert方法
/*
* 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)
@bookybooky
bookybooky / add_search_documents.java
Last active March 18, 2017 05:01
实现两个方法,一个是add document,document都是字符串。再一个就是搜索,支持 AND OR的搜索。返回符合条件的document
// 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;
@bookybooky
bookybooky / Char of Median Frequency.java
Created March 18, 2017 04:57
给一个string list, 例如:['a', 'b', 'b', 'c', 'c', 'e', 'e', 'e'],返回出次次数是中位数的字符。例如本题,应该返回[b, c]
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;
}
}
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();