02 2021 档案

摘要:LeetCode168:168. Excel表列名称 - 力扣(LeetCode) (leetcode-cn.com) 看了题解,计算除以26的商和余数,利用ASCII码从最后一位依次往前计算。 目前还有一点不明白,第5行。 1 class Solution: 2 def convertToTitl 阅读全文
posted @ 2021-02-24 21:10 vv_869 阅读(221) 评论(0) 推荐(0) 编辑
摘要:torch.mul作element-wise的矩阵点乘,维数不限,可以矩阵乘标量 点乘都是broadcast的,可以用 torch.mul(a, b) 实现,也可以直接用 * 实现。 当a, b维度不一致时,会自动填充到相同维度相点乘。 1 import torch 2 3 a = torch.on 阅读全文
posted @ 2021-02-23 22:39 vv_869 阅读(6943) 评论(0) 推荐(1) 编辑
摘要:LeetCode136:https://leetcode-cn.com/problems/single-number/submissions/ 解题思路:参考题解,利用异或 。即将所有数字异或,然后相同的数字消除为0,剩下的即为所求。 1 class Solution: 2 def singleNu 阅读全文
posted @ 2021-02-20 17:07 vv_869 阅读(82) 评论(0) 推荐(0) 编辑
摘要:LeetCode119:https://leetcode-cn.com/problems/pascals-triangle-ii/submissions/ 解题思路:在原来LeetCode118的基础上稍微修改了一下。 1 class Solution: 2 def getRow(self, row 阅读全文
posted @ 2021-02-19 17:38 vv_869 阅读(108) 评论(0) 推荐(0) 编辑
摘要:LeetCode67:https://leetcode-cn.com/problems/add-binary/submissions/ 思路:利用内置函数 1 class Solution: 2 def addBinary(self, a: str, b: str) -> str: 3 return 阅读全文
posted @ 2021-02-19 16:45 vv_869 阅读(72) 评论(0) 推荐(0) 编辑
摘要:LeetCode58:https://leetcode-cn.com/problems/length-of-last-word/ 解题思路:利用字符串的内置函数 1 class Solution: 2 def lengthOfLastWord(self, s: str) -> int: 3 retu 阅读全文
posted @ 2021-02-19 11:53 vv_869 阅读(85) 评论(0) 推荐(0) 编辑
摘要:LeetCode35:https://leetcode-cn.com/problems/search-insert-position/ 解题思路:一种比较笨的方法,直接比较 # 先判断数字是否在给定的数组中 # 若在:遍历数组,找到该元素,并返回下标 # 若不在:遍历数组,比较大小,返回插入位置的索 阅读全文
posted @ 2021-02-18 18:41 vv_869 阅读(68) 评论(0) 推荐(0) 编辑
摘要:LeetCode28:https://leetcode-cn.com/problems/implement-strstr/submissions/ 解题思路:滑动窗法 1 class Solution: 2 def strStr(self, haystack: str, needle: str) - 阅读全文
posted @ 2021-02-18 16:52 vv_869 阅读(66) 评论(0) 推荐(0) 编辑