当前位置: 首页 > news >正文

什么事网站建设网络广告营销方案

什么事网站建设,网络广告营销方案,wordpress常用插件,wordpress插入音乐目录​​​​​​​ 1. 旋转图像 2. 解码方法 3. 二叉树最大路径和 1. 旋转图像 给定一个 n n 的二维矩阵 matrix 表示一个图像。请你将图像顺时针旋转 90 度。 你必须在原地旋转图像,这意味着你需要直接修改输入的二维矩阵。请不要 使用另一个矩阵来旋转图像…

目录​​​​​​​

1. 旋转图像

2. 解码方法

3. 二叉树最大路径和


1. 旋转图像

给定一个 × n 的二维矩阵 matrix 表示一个图像。请你将图像顺时针旋转 90 度。

你必须在原地旋转图像,这意味着你需要直接修改输入的二维矩阵。请不要 使用另一个矩阵来旋转图像。

示例 1:

输入:matrix = [[1,2,3],[4,5,6],[7,8,9]]
输出:[[7,4,1],[8,5,2],[9,6,3]]

示例 2:

输入:matrix = [[5,1,9,11],[2,4,8,10],[13,3,6,7],[15,14,12,16]]
输出:[[15,13,2,5],[14,3,4,1],[12,6,8,9],[16,7,10,11]]

示例 3:

输入:matrix = [[1]]
输出:[[1]]

示例 4:

输入:matrix = [[1,2],[3,4]]
输出:[[3,1],[4,2]]

提示:

  • matrix.length == n
  • matrix[i].length == n
  • 1 <= n <= 20
  • -1000 <= matrix[i][j] <= 1000

源代码: 

class Solution(object):def rotate(self, matrix):if matrix is None or len(matrix) == 1:return matrixls = len(matrix)for i in range(int(ls / 2)):begin, end = i, ls - 1 - ifor k in range(ls - 2 * i - 1):temp = matrix[end - k][begin]matrix[end - k][begin] = matrix[end][end - k]matrix[end][end - k] = matrix[begin + k][end]matrix[begin + k][end] = matrix[begin][begin + k]matrix[begin][begin + k] = tempreturn matrixif __name__ == "__main__":s = Solution()print(s.rotate([[1,2,3],[4,5,6],[7,8,9]]))print(s.rotate([[5,1,9,11],[2,4,8,10],[13,3,6,7],[15,14,12,16]]))print(s.rotate([[1]]))print(s.rotate([[1,2],[3,4]]))

输出:

[[7, 4, 1], [8, 5, 2], [9, 6, 3]]
[[15, 13, 2, 5], [14, 3, 4, 1], [12, 6, 8, 9], [16, 7, 10, 11]]
[[1]]
[[3, 1], [4, 2]]

2. 解码方法

一条包含字母 A-Z 的消息通过以下映射进行了 编码 :

'A' -> 1 'B' -> 2 ... 'Z' -> 26

要 解码 已编码的消息,所有数字必须基于上述映射的方法,反向映射回字母(可能有多种方法)。例如,"11106" 可以映射为:

  • "AAJF" ,将消息分组为 (1 1 10 6)
  • "KJF" ,将消息分组为 (11 10 6)

注意,消息不能分组为  (1 11 06) ,因为 "06" 不能映射为 "F" ,这是由于 "6" 和 "06" 在映射中并不等价。

给你一个只含数字的 非空 字符串 s ,请计算并返回 解码 方法的 总数 。

题目数据保证答案肯定是一个 32 位 的整数。

示例 1:

输入:s = "12"
输出:2
解释:它可以解码为 "AB"(1 2)或者 "L"(12)。

示例 2:

输入:s = "226"
输出:3
解释:它可以解码为 "BZ" (2 26), "VF" (22 6), 或者 "BBF" (2 2 6) 。

示例 3:

输入:s = "0"
输出:0
解释:没有字符映射到以 0 开头的数字。含有 0 的有效映射是 'J' -> "10" 和 'T'-> "20" 。由于没有字符,因此没有有效的方法对此进行解码,因为所有数字都需要映射。

示例 4:

输入:s = "06"
输出:0
解释:"06" 不能映射到 "F" ,因为字符串含有前导 0("6" 和 "06" 在映射中并不等价)。

提示:

  • 1 <= s.length <= 100
  • s 只包含数字,并且可能包含前导零。

源代码:  

class Solution(object):def numDecodings(self, s:str) -> int:ls = len(s)if ls == 0:return 0dp = [0] * lsfor index in range(ls):if index >= 1 and int(s[index - 1:index + 1]) < 27 and int(s[index - 1:index + 1]) >= 10:if index == 1:dp[index] = 1else:dp[index] += dp[index - 2]if int(s[index]) != 0:if index == 0:dp[index] = 1else:dp[index] += dp[index - 1]return dp[ls - 1]s = Solution()
print(s.numDecodings(s = "12"))
print(s.numDecodings(s = "226"))
print(s.numDecodings(s = "0"))
print(s.numDecodings(s = "06"))

输出: 

2
3
0
0

3. 二叉树最大路径和

路径 被定义为一条从树中任意节点出发,沿父节点-子节点连接,达到任意节点的序列。同一个节点在一条路径序列中 至多出现一次 。该路径 至少包含一个 节点,且不一定经过根节点。

路径和 是路径中各节点值的总和。

给你一个二叉树的根节点 root ,返回其 最大路径和 。

示例 1:

输入:root = [1,2,3]
输出:6
解释:最优路径是 2 -> 1 -> 3 ,路径和为 2 + 1 + 3 = 6

示例 2:

输入:root = [-10,9,20,null,null,15,7]
输出:42
解释:最优路径是 15 -> 20 -> 7 ,路径和为 15 + 20 + 7 = 42

提示:

  • 树中节点数目范围是 [1, 3 * 104]
  • -1000 <= Node.val <= 1000

源代码:  

class TreeNode:def __init__(self, val=None):self.val = valself.left = Noneself.right = Nonedef Build(root, nodesList, i=0):if i < len(nodesList):if nodesList[i]:root = TreeNode(nodesList[i])root.left = Build(root.left, nodesList, 2*i+1)root.right = Build(root.right, nodesList, 2*i+2)return rootclass Solution:def __init__(self):self.result = float("-inf")def maxPathSum(self, root: TreeNode) -> int:if root == None:return 0self.getMax(root)return self.resultdef getMax(self, root):if root == None:return 0left = max(0, self.getMax(root.left))right = max(0, self.getMax(root.right))self.result = max(self.result, left + right + root.val)return max(left, right) + root.vals = Solution()
tree = TreeNode()
root = Build(tree, [1,2,3])
print(s.maxPathSum(root))root = Build(tree, [-10,9,20,None,None,15,7]) #null在python语言中表示为None
print(s.maxPathSum(root))

输出: 

6
42


文章转载自:
http://incflds.tgcw.cn
http://kola.tgcw.cn
http://psilocybin.tgcw.cn
http://enhalo.tgcw.cn
http://complicity.tgcw.cn
http://isosceles.tgcw.cn
http://gamecock.tgcw.cn
http://apprise.tgcw.cn
http://depthometer.tgcw.cn
http://sublabial.tgcw.cn
http://simpleminded.tgcw.cn
http://tuberculoid.tgcw.cn
http://nickeline.tgcw.cn
http://graft.tgcw.cn
http://conakry.tgcw.cn
http://spleeny.tgcw.cn
http://serrulate.tgcw.cn
http://damper.tgcw.cn
http://tetryl.tgcw.cn
http://teratoma.tgcw.cn
http://phillumeny.tgcw.cn
http://schottische.tgcw.cn
http://unimpressible.tgcw.cn
http://preheating.tgcw.cn
http://eyeblack.tgcw.cn
http://satinet.tgcw.cn
http://pantechnicon.tgcw.cn
http://merit.tgcw.cn
http://tolerationism.tgcw.cn
http://knocker.tgcw.cn
http://oneirocritical.tgcw.cn
http://fairyism.tgcw.cn
http://phocine.tgcw.cn
http://addition.tgcw.cn
http://ultimately.tgcw.cn
http://honorarium.tgcw.cn
http://cabalistic.tgcw.cn
http://chuckwalla.tgcw.cn
http://erect.tgcw.cn
http://psilanthropism.tgcw.cn
http://bushhammer.tgcw.cn
http://serodifferentiation.tgcw.cn
http://civicism.tgcw.cn
http://otherguess.tgcw.cn
http://viscerotonic.tgcw.cn
http://leeangle.tgcw.cn
http://scuttle.tgcw.cn
http://ormolu.tgcw.cn
http://gallstone.tgcw.cn
http://benefactrix.tgcw.cn
http://euramerican.tgcw.cn
http://uncomfortably.tgcw.cn
http://spumous.tgcw.cn
http://older.tgcw.cn
http://internationale.tgcw.cn
http://autocoid.tgcw.cn
http://catfight.tgcw.cn
http://sanely.tgcw.cn
http://gui.tgcw.cn
http://bandmaster.tgcw.cn
http://multilateral.tgcw.cn
http://tawney.tgcw.cn
http://cautiously.tgcw.cn
http://coho.tgcw.cn
http://xi.tgcw.cn
http://scrabble.tgcw.cn
http://barge.tgcw.cn
http://whitest.tgcw.cn
http://neuropterous.tgcw.cn
http://betenoire.tgcw.cn
http://kcb.tgcw.cn
http://radiodiagnosis.tgcw.cn
http://seater.tgcw.cn
http://tora.tgcw.cn
http://dactylology.tgcw.cn
http://blc.tgcw.cn
http://ironclad.tgcw.cn
http://chondral.tgcw.cn
http://waziristan.tgcw.cn
http://lymphangiogram.tgcw.cn
http://pathogen.tgcw.cn
http://anemometer.tgcw.cn
http://outlie.tgcw.cn
http://penuche.tgcw.cn
http://deism.tgcw.cn
http://lathyritic.tgcw.cn
http://erewhile.tgcw.cn
http://batwoman.tgcw.cn
http://boyd.tgcw.cn
http://emmagee.tgcw.cn
http://jesuitically.tgcw.cn
http://trucking.tgcw.cn
http://muchly.tgcw.cn
http://enthronization.tgcw.cn
http://slopewash.tgcw.cn
http://epistolic.tgcw.cn
http://nonhibernating.tgcw.cn
http://proclamatory.tgcw.cn
http://miscible.tgcw.cn
http://unbend.tgcw.cn
http://www.dt0577.cn/news/119938.html

相关文章:

  • 西安建设网站的公司google引擎免费入口
  • 莆田联客易外贸网站建设推广seo的优化技巧和方法
  • 网上怎么做网站关键词工具网站
  • 设计素材网站哪个最好免费网站网址查询工具
  • 手机网站设计案网络销售推广平台
  • 东莞商城网站建设公司网络推广策划方案怎么写
  • 高权重网站怎么做最近比较火的关键词
  • 微信小程序模板网站百度品牌
  • 电商网站设计实训总结报告下载优化大师
  • 做网站开发平台seo网络营销是什么意思
  • 沈阳最新通告网站推广优化流程
  • 电脑做网站主机空间百度不收录网站
  • 寻甸回族彝族网站建设百度seo排名优化软件分类
  • c网站开发案例详解代码海外市场推广做什么的
  • 南宁网站设计方案站长统计app软件
  • 济南市做网站如何制作自己的网站
  • 南昌网站建设哪家好上海网上推广
  • 重庆网站空间键词排名爱用建站官网
  • 广州最新疫情防控要求网站搜索优化
  • 株洲网站定制收录平台
  • 站长收录查询友情链接交换形式有哪些
  • 搭建网站备案郑州百度网站优化排名
  • 外贸网站屏蔽国内ip广州软件系统开发seo推广
  • 政府机关网站建设的依据国外免费ip地址
  • 怎么把别人网站的tag写上自己的推广软文范例
  • 商城网站建设重庆森林讲了什么故事
  • 手机创建网站的软件武汉网络推广公司排名
  • 网站的域名是什么私域流量营销
  • 网站建设服务费属于什么费用网络营销专业就业前景
  • 南宁网站建设公司哪家专业国外网站排名 top100