Skip to content

Instantly share code, notes, and snippets.

@rioshen
rioshen / psp_url.md
Last active August 29, 2015 14:16
psp
  1. 先查看版本信息
  2. 升级系统的前需要格式化内存记忆棒
  3. 美版 psp3000 直接用到国内的越狱版本 pro
  4. 下载游戏,多玩游戏有,我是从115网盘下的,居然要装一个浏览器才能下载
  5. 用数据线连上电脑,在 USB 上建一个 ISO 文件夹,然后把下载然后解压的 iso 文件拷贝过去
@rioshen
rioshen / coding-tips.md
Last active August 29, 2015 14:16
编程时的小细节

Two Pointers 判断两个变量的条件一定要用小于

Tow Pointers 通常要使用两个变量 lo, hi 或者 left, right 来从两个方向遍历数组,循环的结束条件一定是 lo < hi,不要用 lo != hi 否则如果 lohi 均为偶数,那么同时操作会导致 hi 小于 lo 以至于循环溢出

void reverse(int[] A, int lo, int hi) {
    while (lo != hi) {
        int temp = A[lo];
        A[lo] = A[hi];
 A[hi] = temp;
@rioshen
rioshen / Intersection.java
Created January 6, 2015 02:09
Find Intersection of Two BST
class TreeNode {
int val;
TreeNode left;
TreeNode right;
public TreeNode(int x) { this.val = x; }
}
public void printIntersection(TreeNode p, TreeNode q) {
if (p == null || q == null) {
@rioshen
rioshen / python_resources.md
Last active August 29, 2015 14:09 — forked from jookyboi/python_resources.md
Python-related modules and guides.

Packages

  • lxml - Pythonic binding for the C libraries libxml2 and libxslt.
  • boto - Python interface to Amazon Web Services
  • Django - Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design.
  • Fabric - Library and command-line tool for streamlining the use of SSH for application deployment or systems administration task.
  • PyMongo - Tools for working with MongoDB, and is the recommended way to work with MongoDB from Python.
  • Celery - Task queue to distribute work across threads or machines.
  • pytz - pytz brings the Olson tz database into Python. This library allows accurate and cross platform timezone calculations using Python 2.4 or higher.

Guides

@rioshen
rioshen / 0_reuse_code.js
Last active August 29, 2015 14:09
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@rioshen
rioshen / lis.py
Created October 18, 2014 23:46
DP 经典问题 1 - LIS
#!/usr/bin/python
# -*- coding: utf-8 -*-
from itertools import combinations
def naive_lis(seq):
'''最长上升子(非下降)序列 Longest Increasing Subsequence,基本解法
首先生成一个序列可能的所有子序列,比如说给定数组[1, 2, 3],那么所有可能的子序列是
[], [1], [2], [3], [1, 2], [1, 3], [2, 3], [1, 2, 3]。
然后从中挑选满足所有上升的子序列。最后算出其中拥有最大长度的一个。
'''
@rioshen
rioshen / Backtrack.java
Created September 24, 2014 00:25
Backtracking Template
public class Backtrack {
public static List<List<Object>> backtrack(int[] A) {
// Set up a list of list to hold all possible solutions
List<List<Object>> result = new LinkedList<List<Object>>();
if (A == null || A.length == 0) {
return result;
}
// As we need to recursively generate every solution,
// a variable is needed to store single solution.
@rioshen
rioshen / arrays.md
Last active August 29, 2015 14:04
Summarization of LeetCode Problems

常用技巧

使用java.util库的函数精简代码

使用Arrays.sort() or Collections.sort()给数组排序

int[] num = {1, 3, 2, 4};
Arrays.sort(num);
@rioshen
rioshen / Java-performance-tunning.md
Last active August 29, 2015 14:04
Java Collection Performane Tunning Tips for Online Challenge.

Based on Java 7.

Sorting

There are two built-in sort() methods, java.util.Arrays.sort() and java.util.Collections.sot(). Typically, we use the first one to sort primitive type and the later one to sort Objects.

For primitive type, the sorting algorithm is a Dual-Pivot Quicksort by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm offers O(n log(n)) performance on many data sets that cause other quicksorts to degrade to quadratic performance, and is typically faster than traditional (one-pivot) Quicksort implementations.

For Objects, the implementation was adapted from Tim Peters's list sort for Python (TimSort). It uses techiques from Peter McIlroy's "Optimistic Sorting and Information Theoretic Complexity", in Proceedings of the Fourth Annual ACM-SIAM Symposium on Discrete Algorithms, pp 467-474, J

@rioshen
rioshen / FindNth.java
Created June 10, 2014 19:44
Find Nth to the last element in the list.
/**
* Problem: Find the nth to the end of the linked list.
*/
public class FindNth {
/**
* Solution:
* A simple math - nth to the end equals to: the length - n
* from the beginning.
* We can first calculate the length of the linked list then print