自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

啊_三雨啊的博客

记录学习过程,不做伸手党

  • 博客(15)
  • 收藏
  • 关注

原创 leetcode. 134. Gas Station

问题描述:There are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i t...

2018-12-19 10:43:36 205

原创 从sklearn开始机器学习

数据集 sklearn中带有一些一些标准的数据集,比如iris dataset,digit dataset。 数据集的引入和加载:$ python>>> from sklearn import datasets>>> iris = datasets.load_iris()>>> digits = datasets.load_d...

2018-05-05 20:50:01 142

原创 Leet Code OJ 127. Word Ladder [Difficulty: Medium]-python3

dictionary查找的优越性 python 中dictionary和list的查找机制不同,dictionary的查找hashmap,时间效率是O(1),list查找是挨个对比时间效率是O(n),所以使用list来查找的话时间效率远不如dictionary乐观。 127这道题,好像是经过多次变迁的题目,之前题目中的的wordlist是dictionary类型,所以这道题如果将list转为...

2018-05-05 15:17:05 251

原创 Leet Code OJ 98. Validate Binary Search Tree [Difficulty: Medium] -python

树的操作:左边比根节点小,右边都比根节点大,不能忽略的所有长辈节点都比左边的子孙节点大,比右边的子孙节点小思路1: 中序遍历,所以遍历之后所有的元素就是一个递增的顺序,只需要检查是不是递增的顺序。使用递归的方法进行中序遍历。# Definition for a binary tree node.class TreeNode(object): def __init__(...

2018-05-03 11:03:07 239

原创 Leet Code OJ 73. Set Matrix Zeroes [Difficulty: Medium] -python3

这道题看起来比较简单,但是重点应该放在空间的优化上。通常的思维是使用List(list(int))来进行存储,那么至少要用到两个,对空间的浪费比较大在数据多的时候。如果利用本来的数组来进行行列是不是有0 的表示的话在空间上就有很大的节约。但是时间上也就相对浪费得多一些了,典型的用时间换取空间。(可是用几个存储的方式在时间上也并没有获得什么优势,希望大家不吝赐教)首先贴一个空间上比较优化的方...

2018-05-03 09:34:36 201

原创 Leet Code OJ 125. Valid Palindrome [Difficulty: Easy]-python

题目描述: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.Note: For the purpose of this problem, we define empty string as valid palindrome....

2018-05-02 12:46:56 234

原创 Leet Code OJ 88. Merge Sorted Array [Difficulty: Easy]-python

题目描述: Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:The number of elements initialized in nums1 and nums2 are m and n respectively. You may ass...

2018-05-02 10:28:58 242

原创 Leet Code OJ 70. Climbing Stairs [Difficulty: Easy] -python3

题目描述: You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? Note: Given n will be a p...

2018-04-30 21:33:45 169

原创 Leet Code OJ 28. Implement strStr() [Difficulty: Easy]

很简单的一道题,普通做法效果也很不错class Solution: def strStr(self, haystack, needle): """ :type haystack: str :type needle: str :rtype: int """ if haystack.coun...

2018-04-30 19:17:02 90

原创 Leet Code OJ 21. Merge Two Sorted Lists [Difficulty: Easy] -python

这道题是基本的链表操作题目,需要额外创造一个新的链表作为结果链表即可。但是设计师几个判断:两个链表是不是都是空 not 在循环中,是不是某一个链表已经为空了 and如果2中某个链表已经为空,就应该停止当前的循环,将链表剩下的部分直接拼接在末尾就可以了。 or class Solution: def mergeTwoLists(self, l1, l2): ...

2018-04-30 17:05:14 137

原创 Leet Code OJ 20. Valid Parentheses [Difficulty: Easy] -- python3

很简单的一道题,考点就是栈的使用,但是题目中有几个陷阱:考虑空输入非空输入保证成对,正常顺序出现非空输入保证出来这几种括号之外没有其他符号的出现可以加入几个提前判断是否非空(第一次没有考虑到非空问题所以就wa了)是不是只含有括号(使用正则表达式)初步判断是不是成对出现,对长度进行判断。在做了基本处理之后,本题的重点就变成判断是不是按照顺序出现。如果是‘{(【...

2018-04-30 15:31:36 166

原创 Leet Code OJ 15. 3Sum [Difficulty: Medium]--python3

**问题描述:**Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:The solution set must ...

2018-04-30 14:01:32 239

原创 Leet Code OJ 8. String to Integer (atoi) [Difficulty: Medium]

这道题是将字符串转为数字,其实是提取字符串中的数字,看起来很简单,但是有很多隐藏的条件:有数字但是这个数字必须在整个串的开始。有数字,但是其中夹杂字母。只考虑字母等符号前面的数字,后面的数字要忽略。需要考虑 + - 符号 和前几位是0的情况。考虑输入为空或者输入中并没有数字的情况。考虑上下界问题。输入的数字是整数还是浮点数解决思路: 因为是要在字符串中提取需要的对象...

2018-04-29 16:33:36 172

原创 Leet Code OJ 1. Two Sum [Difficulty: Easy]---把题目的加法变成减法思维

思路解析:看到这道题的惯性思维就是寻找里面两个和为target的数,这就是暴力的方法。即使是根据target的范围来缩小了查找的范围,仍然要使用平方级别的时间。 换个思路:如果将target和当前的元素来进行做差得到的结果是否在剩下的元素中,就能够大大缩小运行的时间了。由于list的index函数在未查到结果时返回的是异常结果,所以考虑使用dictionary结构。但是dictionary结构的...

2018-04-25 16:07:23 211

原创 log数求和与和求log之间的转换tips

HMM学习过程中,使用统计的方法来求HMM的三个参数λ(π,A,B)时,通常会使用使用log归一化,归一化之后的结果成为概率的代替。因此在整个HMM计算过程中的概率都应该变为log形式的数。归一化原式:A1+A2+A3+…An = M 普通归一化:A1/M+A2/M+A3/M+…An/M = 1 如果要对其中的每个项做log,那么原式log(A1/M)=logA1-...

2018-04-22 16:30:44 7151

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除