04 2016 档案

摘要:分治法两两合并,才没有超时 阅读全文
posted @ 2016-04-07 17:44 colors 阅读(256) 评论(0) 推荐(0)
摘要:#!/usr/bin/env python # -*- coding: utf-8 -*- # 将前l个节点构成的树的第i个节点调整为大顶堆 # base 1 def heap_adjust(lists,i,l): left,right=2*i-1,2*i max=i-1 if left<l and lists[max]<lists[left]: max... 阅读全文
posted @ 2016-04-07 16:41 colors 阅读(663) 评论(0) 推荐(0)
摘要:笨笨的回溯 感觉自己代码很丑。。 阅读全文
posted @ 2016-04-06 16:48 colors 阅读(413) 评论(0) 推荐(0)
摘要:链表操作,只能遍历一遍然后。 用双指针 阅读全文
posted @ 2016-04-06 14:08 colors 阅读(447) 评论(0) 推荐(0)
摘要:笨方法回溯啦 阅读全文
posted @ 2016-04-06 10:58 colors 阅读(231) 评论(0) 推荐(0)
摘要:先排序,再循环遍历,用双指针。 阅读全文
posted @ 2016-04-05 17:40 colors 阅读(1565) 评论(0) 推荐(0)
摘要:class Solution(object): def longestCommonPrefix(self, strs): """ :type strs: List[str] :rtype: str """ if len(strs)==0: return "" resul... 阅读全文
posted @ 2016-04-05 17:17 colors 阅读(873) 评论(0) 推荐(1)
摘要:class Solution(object): def romanToInt(self, s): """ :type s: str :rtype: int """ l=len(s) r,i=0,0 roman={'I':1,'V':5,'X':10,'L':50,'C':100,'D':500,... 阅读全文
posted @ 2016-04-05 14:57 colors 阅读(220) 评论(0) 推荐(0)
摘要:class Solution(object): def intToRoman(self, num): """ :type num: int :rtype: str """ M=["","M","MM","MMM"] C=["","C","CC","CCC","CD","D","DC","DCC",& 阅读全文
posted @ 2016-04-05 14:52 colors 阅读(214) 评论(0) 推荐(0)
摘要:用双指针left、right,分别指向数组height的首尾。 如果i的长度小于j,无论如何移动j,短板在i,不可能找到比当前记录的area更大的值了,只能通过移动i来找到新的可能的更大面积 阅读全文
posted @ 2016-04-05 10:05 colors 阅读(185) 评论(0) 推荐(0)
摘要:判断一个整数是否是回文数。不可以用额外的空间 我的思路很简单。就是计算首和尾,检测是否相同 阅读全文
posted @ 2016-04-05 10:01 colors 阅读(183) 评论(0) 推荐(0)
摘要:该题比较简单,但是这道题有点问题。。。。 python中的整数运算没有没有限制,但是在该oj系统中要求对大数输出0(题目并没有说明,但是在test case中可以看出) 于是偷了个懒,,, 阅读全文
posted @ 2016-04-04 16:33 colors 阅读(129) 评论(0) 推荐(0)
摘要:这个想法很简单,用一个列表表示每一行的字符串,最后再输出即可。 重点是找规律。 阅读全文
posted @ 2016-04-04 16:22 colors 阅读(193) 评论(0) 推荐(0)
摘要:二叉树的中序遍历 迭代实现,用栈: 递归实现: 阅读全文
posted @ 2016-04-02 21:04 colors 阅读(803) 评论(0) 推荐(0)