原创 CUDA中的常量內存__constant__和cudaMemcpyToSymbol
__constant__聲明內存爲常量內存 使用常量內存可以提升運算性能的原因如下: 對常量內存的單次讀操作可以廣播到其他的“鄰近(nearby)”線程,這將節約15次讀取操作; 高速緩存。常量內存的數據將緩存起來,因此對於相同地址的連續
原创 cudaMallocPitch和cudaMalloc3D用法
cudaMallocPitch: cudaMalloc3D:
原创 迴文鏈表
題目說要時間複雜度O(n),空間複雜度O(1)的解法,我沒做出來。。。 我的解法就是簡單的把問題轉化爲迴文數列:速度倒是很快,就是空間佔用很高使用了一個result保存所有值 # Definition for singly-linked
原创 合併兩個有序鏈表
# Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # s
原创 環形鏈表
空間複雜度O(1): 快指針追上慢指針即可確定有迴環 # Definition for singly-linked list. # class ListNode: # def __init__(self, x): #
原创 刪除鏈表的倒數第N個節點
我的方法是用一個隊列,保存後N個節點,但是內存消耗比較大,方法如下: # Definition for singly-linked list. # class ListNode: # def __init__(self, x):
原创 外觀數列
class Solution: def countAndSay(self, n: int) -> str: if n == 1: return "1" e
原创 驗證迴文串
class Solution: def isPalindrome(self, s: str) -> bool: s = s.lower() i = 0 j = l
原创 有效的字母異位詞
collections中的Counter真是香。。。 class Solution: def isAnagram(self, s: str, t: str) -> bool: from coll
原创 旋轉圖像
順時針90°旋轉先轉置,再對每行反轉 逆時針90°相反 class Solution: def rotate(self, matrix: List[List[int]]) -> None: """
原创 填充每個節點的下一個右側節點指針 II
迭代方法,(遇到了一個超長的測試用例,結果超時了。。。。。): """ # Definition for a Node. class Node: def __init__(self, val: int = 0, left: 'N
原创 螺旋矩陣
class Solution: def spiralOrder(self, matrix: List[List[int]]) -> List[int]: if not matrix: re
原创 二進制求和
class Solution: def addBinary(self, a: str, b: str) -> str: return bin(int(a, 2) + int(b, 2))[2:] 超簡單
原创 爬樓梯
遞歸解法: class Solution: def climbStairs(self, n: int) -> int: cache = {} return self.climb(n, cache)
原创 旋轉數組
自己寫的方法,不太好: class Solution: def rotate(self, nums: List[int], k: int) -> None: """ Do not return a