Leetcode 141: Linked List Cycle

Linked List Cycle   Total Accepted: 74414 Total Submissions: 204066 Difficulty: Medium Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using extra space? https://leetcode.com/problems/linked-list-cycle/   Naive: O(N) space, O(N) time # Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # self.val …

Leetcode 282: Expression Add Operators

Expression Add Operators https://leetcode.com/problems/expression-add-operators/ Given a string that contains only digits 0-9 and a target value, return all possibilities to add operators +, -, or * between the digits so they evaluate to the target value. Examples: “123”, 6 -> [“1+2+3”, “1*2*3”] “232”, 8 -> [“2*3+2”, “2+3*2”] “00”, 0 -> [“0+0”, “0-0”, “0*0”] “3456237490”, 9191 …

How to remote access mysql via ssh

You need to let mysql listening on the whole Internet (or the IP address you want to restrict to). By default mysql only allows inbound traffic from localhost. To configure that, first you need to locate the configuration file that mysql takes mysql –help –verbose | more # You will find a paragraph like: Default …

You are almost always getting significant p-value in large dataset

Recently, an exploding reproducibility research paper [1] shows that more than half of past published papers in the main psychological journals can’t be replicated to generate significance findings. This makes me dig a little further on how to conduct statistical tests. Let me show you my little experiments in `R` first. # remove(list=ls()) set.seed(19910715) n1 …

How to to write multi-lined subscript in latex?

In latex, what is the best way to write multi-lined formula in subscript? Use `\atop`! For example, \begin{align*} P(M_n=1) =\sigma(&w_s(\sum\limits_{j_r \in T_{nr}}\vec{U_{j_r}} \cdot \vec{C_{j_r}} – \sum\limits_{j_b \in T_{nb}}\vec{U_{j_b}} \cdot \vec{C_{j_b}} ) + \\ &w_b(\sum\limits_{j_{r_1}, j_{r_2} \in T_{nr} \atop j_{r_1} \neq j_{r_2} }\left\Vert\vec{C_{j_{r_1}}} – \vec{C_{j_{r_2}}}\right\Vert^2 – \sum\limits_{j_{b_1}, j_{b_2} \in T_{nb} \atop j_{b_1} \neq j_{b_2} }\left\Vert\vec{C_{j_{b_1}}} – …

How to write multi-lined formula?

In latex, what is the best way to write multi-lined formula? Actually, the `begin/end{align*}` block supports `\\\` in it. For example, \begin{align*} P(M_n=1) =\sigma(&w_s(\sum\limits_{j_r \in T_{nr}}\vec{U_{j_r}} \cdot \vec{C_{j_r}} – \sum\limits_{j_b \in T_{nb}}\vec{U_{j_b}} \cdot \vec{C_{j_b}} ) + \\ &w_b(\sum\limits_{j_{r_1}, j_{r_2} \in T_{nr} \atop j_{r_1} \neq j_{r_2} }\left\Vert\vec{C_{j_{r_1}}} – \vec{C_{j_{r_2}}}\right\Vert^2 – \sum\limits_{j_{b_1}, j_{b_2} \in T_{nb} \atop j_{b_1} …

Minimum Description Length (MDL): a scoring function to learn Bayesian Network Structure

Bayesian Network Augmented Naive-Bayes (BAN) is an improved version of Naive-Bayes, in which every attribute $latex X_i$ may have at most one other attribute as its parent other than the class variable $latex C$. For example (figure from [1]): Though BAN provides a more flexible structure compared to Naive Bayes, the structure (i.e., dependence/independence relationships …

A viewer for Python Dict

Just found a beautiful viewer library that helps you view Python Dict object. Here is the code: “”” Created on Fri Feb 22 12:52:28 2013 @author: kranzth “”” from traits.api \ import HasTraits, Instance, Str, on_trait_change from traitsui.api \ import View, VGroup, Item, ValueEditor, TextEditor from copy import deepcopy class DictEditor(HasTraits): SearchTerm = Str() Object …

How to run a PPTP VPN server?

Setting up a VPN using PPTP protocal can be vulnerable for security. Yet it is an easy and quick way to set up a virtual private network (VPN). The procedure to setup up a PPTP VPN server can be found here:  https://help.ubuntu.com/community/PPTPServer The way to connect to a PPTP server on a client machine can …