Skip to content

Instantly share code, notes, and snippets.

@gitzhou
gitzhou / max-length-of-none-desc-sequence
Last active August 29, 2015 14:06
max-length-of-none-desc-sequence
#include <iostream>
#include <algorithm>
using namespace std;
int main(int argc, const char * argv[]) {
const int COUNT = 10;
int sequence[COUNT] = {7, 3, 4, 5, 1, 4, 2, 4, 6, 3};
int length[COUNT];
for (int i = 0; i < COUNT; ++i) {
int max = 1;
@gitzhou
gitzhou / fetch-src-push-github.sh
Last active August 29, 2015 14:07
fetch-src-push-github.sh
#!/bin/sh
fetch_dir="/home/aaron67/prj/FetchLeetcodeSubmission/release"
src_dir="/home/aaron67/prj/leetcode-oj-submissions"
# 更新
cd $src_dir
/usr/bin/git pull
# 抓取
cd $fetch_dir
/usr/bin/git pull
/usr/bin/java -jar FetchLeetcodeSubmission.jar
@gitzhou
gitzhou / UserStatistics.java
Created October 23, 2014 15:19
UserStatistics.java
package cc.aaron67.test;
import java.util.ArrayList;
import java.util.List;
public class UserStatistics {
private static List<User> userList;
public static void main(String[] args) {
@gitzhou
gitzhou / f-x-y-recursion
Created October 31, 2014 15:56
f(x, y) = f(x - 1, y) + f(x, y - 1)
#include <iostream>
#include <vector>
using namespace std;
class Solution {
public:
int f(int x, int y) {
vec.resize(x + 1);
for (int i = 0; i < x + 1; ++i) {
vec[i] = vector<int>(y + 1, 0);
class LRUCache{
public:
LRUCache(int capacity) {
m_capacity = capacity;
}
int get(int key) {
if (m_dic.count(key) == 1) { // key存在
int value = m_dic[key]->second; // 取对应的value
m_cache.erase(m_dic[key]); // 在cache-list中删掉元素
@gitzhou
gitzhou / split.cpp
Created March 3, 2015 17:59
C++ split function
vector<int> &split(const string &s, char delim, vector<int> &elems) {
stringstream ss(s);
string item;
while(getline(ss, item, delim)) {
elems.push_back(atoi(item.c_str()));
}
return elems;
}
@gitzhou
gitzhou / skate-shoes-rent-system.c
Created September 6, 2015 15:02
北方工业大学-计算机系-大一-小学期-冰鞋管理系统-C代码
//
// skate-shoes-rent-system
//
// Created by aaron67 on 15/9/6.
// Copyright (c) 2015年 aaron67. All rights reserved.
//
// Mac OS X Yosemite环境测试可用
// 在可执行文件相同路径下,新建文件
// - rent.dat
// - shoes.dat
@gitzhou
gitzhou / director-random-distribute-via-weight-0.cpp
Last active October 14, 2015 05:12
随机-按权值-分发消息队列中的消息-消息队列内消息总数已知
//
// main.cpp
// director-random-distribute-via-weight-0
//
// 有 N 个消费者,分别有相应的权值
// 随机分发消息队列中的消息
// 各个消费者消费的消息数量的比值,总体近似为权值的比值
//
// Created by aaron67 on 15/10/13.
// Copyright © 2015年 aaron67. All rights reserved.
@gitzhou
gitzhou / director-random-distribute-via-weight-2.cpp
Last active October 14, 2015 05:25
随机-按权值-分发消息队列中的消息-消息队列内消息总数未知
//
// director-random-distribute-via-weight-2
//
// 有 N 个消费者,分别有相应的权值
// 随机分发消息队列中的消息
// 各个消费者消费的消息数量的比值,总体近似为权值的比值
//
#include <iostream>
#include <vector>
@gitzhou
gitzhou / director-random-distribute-via-weight-1.cpp
Created October 14, 2015 05:16
随机-按权值-分发消息队列中的消息-消息队列内消息总数未知
//
// director-random-distribute-via-weight-1
//
// 有 N 个消费者,分别有相应的权值
// 随机分发消息队列中的消息
// 各个消费者消费的消息数量的比值,总体近似为权值的比值
//
#include <iostream>
#include <vector>