
python
ep_mashiro
日拱一卒,功不唐捐
展开
-
ubuntu 下装feedparser
==不能当自己是妹纸==为了装Universal Feed Parser,先装了setuptools下载sudo wget https://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz#md5=7df2a529a074f613b509fb44feefe74e解压sudo原创 2015-04-28 21:58:49 · 1319 阅读 · 0 评论 -
优化问题Optimization
优化技术特别擅长用于处理:受多种变量的影响,存在许多可能解的问题,以及结果因这些变量的组合而产生很大变化的问题。 优化算法的典型应用场景,存在大量可能的题解以至于我们无法对它们进行一一尝试的情况。 既然无法一一尝试,怎么做?成本函数(The Cost Function) 量化解的优劣,要求是函数返回的值越大,表示该方案越差。随机搜索(Random Searching) 很简单(tubie原创 2015-11-26 14:56:30 · 1361 阅读 · 0 评论 -
python 学习笔记(相似性计算方法)
实在不能理解为啥搜狗输入法每次我打biji的时候总是给我跳出荸荠(qi) (づ ̄ 3 ̄)づ,还有biaoshi,总是出标识(zhi)..╭(╯^╰)╮哼基于距离的相似度计算 prefs[person][item] 数据集格式如下: example: aaaa={‘WANG’:{‘Lady in the Water’:3,’HAHA story’:2},…} from math imp原创 2015-11-30 10:26:10 · 4135 阅读 · 0 评论 -
Document Filtering(naive bayes method) used by python
The algorithms we mentioned can solve the more general problem of learning to recognize whether a document belongs in one category or another. Early attempts to filter spam were all rule-based classi原创 2015-11-28 16:45:22 · 426 阅读 · 0 评论 -
leetcode84: Largest Rectangle in Histogram
84. Largest Rectangle in Histogram height的内容是 [5,6,7,8,3],特点是除了最后一个,前面全部保持递增,且最后一个立柱的高度小于前面所有立柱高度。对于这种特点的柱状图,如果使用上面所说的“挨个使用每一个柱状图的高度作为矩形的高度,求面积”的方法,还需要用嵌套循环吗?我们知道除了最后一个,从第一个到倒数第二个立柱的高度都在升高,那么如果挨个使用每一个原创 2016-01-19 19:00:29 · 437 阅读 · 0 评论 -
leetcode 20 Valid Parentheses
Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[’ and ‘]’, determine if the input string is valid.The brackets must close in the correct order, “()” and “()[]{}” are all valid but “原创 2016-01-19 19:01:48 · 229 阅读 · 0 评论 -
leetcode32 Longest Valid Parentheses
Given a string containing just the characters ‘(’ and ‘)’, find the length of the longest valid (well-formed) parentheses substring.For “(()”, the longest valid parentheses substring is “()”, which has原创 2016-01-19 19:02:55 · 273 阅读 · 0 评论 -
leetcode150 Evaluate Reverse Polish Notation
Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expression.Some examples: [“2”, “1”, “+”, “3”, ““]原创 2016-01-19 19:04:06 · 241 阅读 · 0 评论 -
leetcode2 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 linke原创 2016-01-21 17:52:30 · 249 阅读 · 0 评论 -
leetcode21. Merge Two Sorted Lists
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.Subscribe to see which companies asked this question 思路: 因原创 2016-01-21 17:56:24 · 230 阅读 · 0 评论 -
coursera公开课——recommender system作业(第三周)
懒虫锅~~~!!!! 原始数据: 以及用户目前对doc的数据 #coding:utf-8import csvimport operatorimport mathcsvfile=file("data1.csv",'rU')reader=csv.reader(csvfile,dialect='excel')doc={}item=[]for line in reader:原创 2016-01-22 17:23:42 · 1090 阅读 · 1 评论 -
leetcode1 Two Sum
Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target, where in原创 2016-01-23 12:31:11 · 270 阅读 · 0 评论 -
leetcode299. Bulls and Cows
You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide a hint that原创 2016-01-23 16:08:19 · 334 阅读 · 0 评论 -
leetcode202. Happy Number
Write an algorithm to determine if a number is “happy”.A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of i原创 2016-01-23 16:36:07 · 317 阅读 · 0 评论 -
leetcode219. Contains Duplicate II
Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between i and j is at most k. 思路 一开原创 2016-01-23 16:59:24 · 309 阅读 · 0 评论 -
leetcode204. Count Primes
Description:Count the number of prime numbers less than a non-negative number, n. javapublic class Solution { public int countPrimes(int n) { boolean[] a= new boolean[n]; for (in原创 2016-01-23 18:33:14 · 342 阅读 · 0 评论 -
Leetcode290. Word Pattern & 205. Isomorphic Strings
Given a pattern and a string str, find if str follows the same pattern.Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str.Examples:原创 2016-01-23 13:46:54 · 377 阅读 · 0 评论 -
leetcode274. H-Index
Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher’s h-index.According to the definition of h-index on Wikipedia: “A scien原创 2016-01-25 09:59:39 · 308 阅读 · 0 评论 -
leetcode18. 4Sum
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note: Elements in a quad原创 2016-01-25 11:46:01 · 285 阅读 · 0 评论 -
leetcode3. Longest Substring Without Repeating 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 is 3. For “原创 2016-01-25 17:37:09 · 262 阅读 · 0 评论 -
leetcode49. Group Anagrams
Given an array of strings, group anagrams together.For example, given: [“eat”, “tea”, “tan”, “ate”, “nat”, “bat”], Return:[ [“ate”, “eat”,”tea”], [“nat”,”tan”], [“bat”] ] Note: For the re转载 2016-01-25 20:22:17 · 316 阅读 · 0 评论 -
n-armed bandit _ ucb1 algorithm
前言:家里发生了一些事情,所以又耽搁了一段时间,这周交的report都有点潦草,好在ucb1本身就不是一个很复杂的算法。 This week, I have studied one of the algorithms in the UCB falmily, which is called the UCB1 algorithm.The UCB1 algorithm pays attention to原创 2016-01-09 10:04:46 · 3472 阅读 · 1 评论 -
leetcode136. Single Number
Given an array of integers, every element appears twice except for one. Find that single one.Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra me原创 2016-01-26 14:22:10 · 256 阅读 · 0 评论 -
leetcode187. Repeated DNA Sequences
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: “ACGAATTCCG”. When studying DNA, it is sometimes useful to identify repeated sequences within the DNA.Write a原创 2016-01-26 15:12:50 · 329 阅读 · 0 评论 -
leetcode166. Fraction to Recurring Decimal
Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.If the fractional part is repeating, enclose the repeating part in parentheses.For exam原创 2016-01-26 20:23:00 · 336 阅读 · 0 评论 -
静态页面的抓取(学习简单爬虫)
圣诞节快乐(づ ̄ 3 ̄)づ~~~在这个半放假的日子里,人也变得慵懒起来,在MOOC下学习了静态页面的简单爬虫(传送门:http://www.imooc.com/learn/563),干货满满啊~~所以爬了一个芈月传么么哒~~~# coding=utf-8import urllib2class UrlManager(object): def __init__(self): s原创 2015-12-25 18:36:57 · 3140 阅读 · 0 评论 -
coursera公开课——recommender system作业(第二周)
写这么丑的代码我也是醉了,继续学习。 第二周的assignment: Mean Rating: Calculate the mean rating for each movie, order with the highest rating listed first, and submit the top 5. % of ratings 4+: Calculate the percen原创 2015-12-27 14:56:23 · 641 阅读 · 1 评论 -
leetcode85 maximal rectangle
Given a 2D binary matrix filled with 0’s and 1’s, find the largest rectangle containing all ones and return its area. 思路: 借鉴了leetcode84 的算法,首先对输入的矩阵进行预处理 一开始没有考虑到输入数据的形式是[‘00’,’00’] 以为是[[0,0原创 2016-02-14 09:59:42 · 323 阅读 · 0 评论 -
leetcode36.Valid Sudoku
The Sudoku board could be partially filled, where empty cells are filled with the character ‘.’. 思路 本题是判断目前九宫给填上的数字是否有效 即:行无重复,列无重复,所在的小九宫格中无重复 所在第几个九宫格:i/3∗3+j/3i/3*3+j/3class Solution(obj原创 2016-02-02 07:08:32 · 274 阅读 · 0 评论 -
python小练习
python 练习代码 练习1: 输入:年、月(1-12)、日(1-31) 打印出相应的月份、名称months=['Janary','February','March','April','May','June','July','August','September','October','November','December']endings=['st','nd','rd']+7*['th原创 2016-03-06 14:38:40 · 359 阅读 · 0 评论 -
python 小练习之山寨版markdown格式txt文件转html文件
本练习根据《python基础教程》课后练习一——《即时标记》改编 分为四个模块(不包括输出部分):文本解析、规则制定、过滤、处理程序,顺序如下: 规则制定 Rule模块由action和condition两部分实现,就是在遍历规则的时候通过调用condition这个东西来判断是否符合当前规则。我们考虑了标题(H1Rule)、引用(GuideRule)、无序列表(ListItemRule&Li原创 2016-03-05 17:43:05 · 1063 阅读 · 0 评论 -
LeetCode65 Valid Number
questionValidate if a given string is numeric.Some examples: “0” => true ” 0.1 ” => true “abc” => false “1 a” => false “2e10” => true Note: It is intended for the problem statement to be ambiguou转载 2015-08-16 19:29:25 · 757 阅读 · 0 评论 -
leetcode26. [Array]Remove Duplicates from Sorted Array
Total Accepted: 117053 Total Submissions: 354699 Difficulty: Easy Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate原创 2016-03-07 20:20:34 · 223 阅读 · 0 评论 -
leetcode 27. [Array]Remove Element
Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn’t matter what you leave beyond the new length.Subscribe原创 2016-03-07 20:21:21 · 236 阅读 · 0 评论 -
leetcode66.[Array] Plus One
Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list.class Solution(object): d原创 2016-03-07 20:22:02 · 233 阅读 · 0 评论 -
leetcode283. [Array]Move Zeroes My Submissions Question
Total Accepted: 61817 Total Submissions: 141889 Difficulty: Easy Given an array nums, write a function to move all 0’s to the end of it while maintaining the relative order of the non-zero elements.Fo原创 2016-03-07 20:22:48 · 257 阅读 · 0 评论 -
leetcode292.[Array] Nim Game
You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will be the原创 2016-03-07 20:23:28 · 244 阅读 · 0 评论 -
leetcode171.[math] Excel Sheet Column Number
Related to question Excel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example:A -> 1B -> 2C -> 3...Z -> 26AA -> 27AB -> 28 clas原创 2016-03-08 21:27:06 · 260 阅读 · 0 评论 -
leetcode264.[DP][math][leep] Ugly Number II
问题描述 Write a program to find the n-th ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of the first 1原创 2016-03-10 18:24:41 · 394 阅读 · 0 评论 -
leetcode263. [Math]Ugly Number
Write a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly since it in原创 2016-03-10 18:26:26 · 290 阅读 · 0 评论