随笔分类 - 算法
摘要:寻找一个数 def binarysearch(nums, target): n = len(nums) if n == 0: return -1 left = 0 right = n - 1 while left <= right: mid = (left + right) // 2 if targ
阅读全文
摘要:139. 单词拆分 https://leetcode-cn.com/problems/word-break/ class Solution(object): def wordBreak(self, s, wordDict): """ :type s: str :type wordDict: List
阅读全文
摘要:https://leetcode-cn.com/problems/increasing-subsequences/ class Solution(object): def findSubsequences(self, nums): """ :type nums: List[int] :rtype:
阅读全文
摘要:https://leetcode-cn.com/problems/palindromic-substrings/ class Solution(object): def countSubstrings(self, s): """ :type s: str :rtype: int """ # 遍历s,
阅读全文
摘要:https://leetcode-cn.com/problems/hanota-lcci/ 先将最底层圆盘之上的圆盘看做一个整体。汉诺塔问题的本质是 将最底层圆盘之上的圆盘全部放到辅助柱上 将最底层圆盘放到目标柱上 递归地处理辅助柱上的圆盘 而第一步又可以变成一个目标柱为辅助柱的汉诺塔问题,即sel
阅读全文
摘要:https://leetcode-cn.com/problems/xuan-zhuan-shu-zu-de-zui-xiao-shu-zi-lcof/ 朴素遍历法 class Solution(object): def minArray(self, numbers): """ :type numbe
阅读全文
摘要:https://leetcode-cn.com/problems/is-graph-bipartite/ 动态维护A、B集合算法 class Solution(object): def isBipartite(self, graph): """ :type graph: List[List[int]
阅读全文
摘要:https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/ 递归。 将数字转换为字符串s。翻译字符串s时,我们有两个选择: 选择将第一位数字翻译成字符。然后翻译剩下的s[1:] 选择将前两位数字翻译成字符。然后翻
阅读全文
摘要:https://leetcode cn.com/problems/find the longest substring containing vowels in even counts/ 这题真的太难了,看答案都想了两个小时,我建议调整难度为困难不过分吧?orz 时间复杂度:O(n) 空间复杂度:O
阅读全文
摘要:题目:https://leetcode cn.com/problems/lfu cache/ 思路: O(1)的数据结构:hashmap 维持最近使用:OrderdDict(详见LRU缓存问题) 使用一个hashmap维系key到出现频率的映射关系 另一个hashmap维系频率到数据(key val
阅读全文
摘要:题目:https://leetcode cn.com/problems/design twitter/ filter切片解法:
阅读全文
摘要:题目:https://leetcode cn.com/problems/trapping rain water/
阅读全文
摘要:题目:https://leetcode cn.com/problems/max area of island/
阅读全文
摘要:题目:https://leetcode cn.com/problems/construct binary tree from preorder and inorder traversal/ 优化:不需要用len(left_inorder)来求元素的数量,root_index就是左数元素的数量了。
阅读全文
摘要:主要记录解题过程,反思如何构思代码。 原题:https://leetcode cn.com/problems/longest palindromic substring 题目: 解题过程 看到这题一开始是完全懵逼的,看着两个例子想了一个错的解法:用两个指针指向字符串的首尾,当两个指针所指的内容相同时
阅读全文
摘要:快排不稳定性体现在,当列表为[5,2,4,6,1,1]时,pivot为5,会把最后一个1与5交换,这样就改变了两个1之间的相对位置 当序列有序时,快排退化为冒泡排序
阅读全文
摘要:卷积神经网络系统结构 PS:在池化层和全链接层之间可以加入多个卷积、激活、池化层 1、CONV:卷积层,用卷积核对输入图像进行卷积处理 2、RELU:激活层,将负值归零 3、池化层:有损压缩,减小图片尺寸 输入带标签的训练数据之后,卷积神经网络会根据输出与训练标签的误差反向调整自身的参数(卷积核和全
阅读全文

浙公网安备 33010602011771号