Skip to content

Instantly share code, notes, and snippets.

View jones's full-sized avatar

Tristan Jones jones

  • Berkeley, CA
View GitHub Profile
@jones
jones / linkedlistintersect.cpp
Created January 1, 2015 10:06
Write a program to find the node at which the intersection of two singly linked lists begins.
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
@jones
jones / pow.py
Created January 1, 2015 05:59
Implement pow(x, n).
class Solution:
# @param x, a float
# @param n, a integer
# @return a float
def pow(self, x, n):
if x == 0.0:
return 0.0
if n < 0:
# Avoids arithmetic underflow
return 1.0/self.pow(x, -n)
@jones
jones / longestcommonprefix.py
Created December 31, 2014 06:25
Write a function to find the longest common prefix string amongst an array of strings.
class Solution:
# @return a string
def longestCommonPrefix(self, strs):
# computes the LCP of the stringlist strs
if strs is None or len(strs) == 0:
return ""
return reduce(self.lcp, strs)
def lcp(self, str1, str2):