Skip to content

Instantly share code, notes, and snippets.

class Rev:
def __init__(self, data):
self.data = data
self.index = len(data)
def __iter__(self):
return self
def __next__(self):
if self.index == 0:
def scope_test():
def do_local():
# print("before local " + spam)
spam = "local spam"
print("do_local: " + spam)
def do_nonlocal():
# print("before non-local: " + spam)
nonlocal spam
spam = "nonlocal spam"
print("do_nonlocal: " + spam)
class Complex:
def __init__(self, real, imag, name):
self.r = real
self.i = imag
self.name = name
name = 'Complex_default'
r = 0.0
i = 1.1
doc = "default doc"
class Complex:
def __init__(self, real, imag, name):
self.r = real
self.i = imag
self.name = name
name = 'Complex_default'
r = 0.0
i = 1.1
doc = "default doc"
def foo(self, num):
@non-static
non-static / TwoSortedArrayMedian.cpp
Last active January 2, 2016 01:19
Median of Two Sorted Arrays http://oj.leetcode.com/problems/median-of-two-sorted-arrays/ There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).
#include <iostream>
using namespace std;
class Solution {
public:
int min(int a, int b)
{
return (a < b) ? a : b;
}
@non-static
non-static / lengthOfLongestSubstring.cpp
Created January 8, 2014 07:05
http://oj.leetcode.com/problems/longest-substring-without-repeating-characters/ Calculating the length of the longest substring without duplicated characters Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length…
#include <string>
#include <map>
#include <iostream>
using namespace std;
class Solution
{
public:
int lengthOfLongestSubstring(string s)
@non-static
non-static / AddTwoNumbers.cpp
Created January 9, 2014 06:37
http://oj.leetcode.com/problems/add-two-numbers/ You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list. Input: (2 -> 4 -> 3) + (5 -> 6 -> 4) Output: 7 -> 0 -> 8
// AddTwoNumbers.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
@non-static
non-static / LongestPalindrome.cpp
Created January 10, 2014 07:18
Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring. http://oj.leetcode.com/problems/longest-palindromic-substring/
// LongestPalindromic.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;
@non-static
non-static / atoi.cpp
Created January 18, 2014 07:35
String to Integer (atoi) Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input cases. Notes: It is intended for this problem to be specified vaguely (ie, no given input specs). You are responsible to gather…
// atoi.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
class Solution
{
@non-static
non-static / isPalindrome.cpp
Created January 20, 2014 08:19
Determine whether an integer is a palindrome. Do this without extra space. http://oj.leetcode.com/problems/palindrome-number/
// PalindromeNumber.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <math.h>
#include <iostream>
using namespace std;