09 2020 档案

摘要:1. 题目描述 2. 代码 1 class Solution: 2 def hammingWeight(self, n: int) -> int: 3 return bin(n).count('1') 思路: 输出的二进制, 直接统计1的个数即可. 3. 语法整理 bin() count() 阅读全文
posted @ 2020-09-30 09:03 vv_869 阅读(73) 评论(0) 推荐(0) 编辑
摘要:1. 题目描述 2. 代码 1 class Solution: 2 def missingNumber(self, nums: List[int]) -> int: 3 nums.sort() #对nums排序 4 prenum = 0 #默认从0开始 5 for x in nums:#遍历排序好的 阅读全文
posted @ 2020-09-29 19:33 vv_869 阅读(95) 评论(0) 推荐(0) 编辑
摘要:1. 题目描述 2. 代码 1 class Solution: 2 def reverseBits(self, n: int) -> int: 3 return int ( bin(n)[2:].zfill(32)[::-1], 2) 思路: 先把输入的整数转换为二进制, 若不够32位则填充上0, 阅读全文
posted @ 2020-09-29 17:33 vv_869 阅读(145) 评论(0) 推荐(0) 编辑
摘要:1. 题目描述 https://leetcode-cn.com/problems/single-number/ 2. 代码 1 class Solution: 2 def singleNumber(self, nums: List[int]) -> int: 3 a = 0 4 for i in n 阅读全文
posted @ 2020-09-26 10:27 vv_869 阅读(101) 评论(0) 推荐(0) 编辑
摘要:1. 题目描述 https://leetcode-cn.com/problems/hamming-distance/ 2. 代码 1 class Solution: 2 def hammingDistance(self, x: int, y: int) -> int: 3 return bin(x 阅读全文
posted @ 2020-09-25 21:47 vv_869 阅读(75) 评论(0) 推荐(0) 编辑
摘要:1. 题目描述 https://leetcode-cn.com/problems/valid-palindrome/ 2. 代码 1 class Solution: 2 def isPalindrome(self, s: str) -> bool: 3 S = list()#定义一个列表,模拟栈 4 阅读全文
posted @ 2020-09-24 20:42 vv_869 阅读(156) 评论(0) 推荐(0) 编辑
摘要:新手小白一个, 简单记录一下过程. 一 一些名词 1. GPU: Graphics Processing Unit, 图形处理器. 2. CUDA: Compute Unified Device Architecture, 是显卡厂商NVIDIA(英伟达)推出的运算平台. CUDA是一种通用并行计算 阅读全文
posted @ 2020-09-23 11:30 vv_869 阅读(186) 评论(0) 推荐(0) 编辑
摘要:1. 题目描述 https://leetcode-cn.com/problems/longest-common-prefix/solution/ 2. 代码 class Solution: def longestCommonPrefix(self, strs: 'List[str]') -> str 阅读全文
posted @ 2020-09-14 21:01 vv_869 阅读(167) 评论(0) 推荐(0) 编辑
摘要:1. 题目描述 https://leetcode-cn.com/problems/pascals-triangle/ 2. 代码 class Solution: def generate(self, numRows: int) -> 'List[List[int]]': result = []#定义 阅读全文
posted @ 2020-09-12 21:37 vv_869 阅读(172) 评论(0) 推荐(0) 编辑