這個思路其實也很簡單,就是把多位數(shù)字的各位拆分成加法的形式,其中每一項可以表示為 原數(shù)字 x 10的n次方。那么這個乘法就變成了兩個多項式相乘,也就是3樓第二步所替換的方法體的含義了
算法題--實現(xiàn)乘法器0. 鏈接 題目鏈接 1. 題目 Given two non-negative integers num1 and num2 represented as strings, ...
這個思路其實也很簡單,就是把多位數(shù)字的各位拆分成加法的形式,其中每一項可以表示為 原數(shù)字 x 10的n次方。那么這個乘法就變成了兩個多項式相乘,也就是3樓第二步所替換的方法體的含義了
算法題--實現(xiàn)乘法器0. 鏈接 題目鏈接 1. 題目 Given two non-negative integers num1 and num2 represented as strings, ...
方法二好像違背了題目的第四點要求的后半句
但此題的限制好像也不是很嚴(yán),所以對于方法一我有個想法:不必用一個數(shù)組去記錄各個數(shù)位上的乘積,直接用一個變量記錄所有經(jīng)轉(zhuǎn)換的乘積之和,最后把這個變量轉(zhuǎn)回字符
算法題--實現(xiàn)乘法器0. 鏈接 題目鏈接 1. 題目 Given two non-negative integers num1 and num2 represented as strings, ...
@歲月如歌2020 [握手][握手]??
算法題--求蓄水池的蓄水量0. 鏈接 題目鏈接 1. 題目 Given n non-negative integers representing an elevation map where the ...
@歲月如歌2020 這個叫“夾逼法”??
算法題--求蓄水池的蓄水量0. 鏈接 題目鏈接 1. 題目 Given n non-negative integers representing an elevation map where the ...
@歲月如歌2020 此法也是從別人那里學(xué)來的,只不過我喜歡去揣摩人家是怎么想到的,或者換個更形象的說法給算法做個解釋
算法題--求蓄水池的蓄水量0. 鏈接 題目鏈接 1. 題目 Given n non-negative integers representing an elevation map where the ...
原題鏈接 思路說明: 把每一個非零列看成不同高度的長條積木:先把積木全拿走(后面的操作會按原來的高矮順序排列),然后把最左側(cè)與最右側(cè)的積木先放回去,這樣就能開始積水了。由于積...
class Solution:
def trap(self, height: List[int]) -> int:
length = len(height)
if length < 1:
return 0
leftMax = 0
rightMax = 0
leftP = 0
rightP = len(height) - 1
leftValue = height[leftP]
rightValue = height[rightP]
count = 0
while leftP < rightP:
if leftValue < rightValue:
if leftValue < leftMax:
count += leftMax - leftValue
else:
leftMax = leftValue
leftP += 1
leftValue = height[leftP]
else:
if rightValue < rightMax:
count += rightMax - rightValue
else:
rightMax = rightValue
rightP -= 1
rightValue = height[rightP]
return count
算法題--求蓄水池的蓄水量0. 鏈接 題目鏈接 1. 題目 Given n non-negative integers representing an elevation map where the ...
0. 鏈接 題目鏈接 1. 題目 Given an unsorted integer array, find the smallest missing positive in...