上一页 1 ··· 41 42 43 44 45 46 47 48 49 ··· 114 下一页
摘要: 依赖倒置原则(Dependence Inversion Principle,DIP)的原始定义为:高层模块不应该依赖低层模块,两者都应该依赖其抽象; 抽象不应该依赖细节,细节应该依赖抽象。 其核心思想是:要面向接口编程,不要面向实现编程。 依赖倒置原则的目的是通过要面向接口的编程来降低类间的耦合性, 阅读全文
posted @ 2019-10-29 14:22 Sempron2800+ 阅读(247) 评论(0) 推荐(0) 编辑
摘要: 接口隔离原则(Interface Segregation Principle,ISP)要求程序员尽量将臃肿庞大的接口拆分成更小的和更具体的接口,让接口中只包含客户感兴趣的方法。 与之前介绍的单一职责原则类似,接口隔离原则同样是为了提高类的内聚性、降低它们之间的耦合性,都是面向对象三个基本特征中的“封 阅读全文
posted @ 2019-10-29 09:46 Sempron2800+ 阅读(186) 评论(0) 推荐(0) 编辑
摘要: 单一职责原则(Single Responsibility Principle,SRP)又称单一功能原则,这里的职责是指类变化的原因。 单一职责原则规定一个类应该有且仅有一个引起它变化的原因,否则类应该被拆分。 以上是单一职责的基本概念,可以看到两句话中两次提到了"变化的原因"。 变化是软件生命周期中 阅读全文
posted @ 2019-10-28 09:30 Sempron2800+ 阅读(203) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution: 2 def longestSubsequence(self, arr: List[int], difference: int) -> int: 3 dp = collections.defaultdict(int) 4 result = 0 5 for val in arr: 6 ... 阅读全文
posted @ 2019-10-21 00:30 Sempron2800+ 阅读(165) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution: 2 def checkStraightLine(self, coordinates: List[List[int]]) -> bool: 3 (u, v), (p, q) = coordinates[: 2] 4 for x, y in coordinates: 5 if (x - u) * (y... 阅读全文
posted @ 2019-10-21 00:24 Sempron2800+ 阅读(123) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution: 2 def missingNumber(self, arr: 'List[int]') -> int: 3 n = len(arr) 4 common = (arr[n-1] - arr[0]) // n 5 if common == 0: 6 return 0 7 for i in range(n): 8 need = arr[0] + common * i 阅读全文
posted @ 2019-10-21 00:07 Sempron2800+ 阅读(200) 评论(0) 推荐(0) 编辑
摘要: 剪绳子 题目描述给你一根长度为n的绳子,请把绳子剪成m段(m、n都是整数,n>1并且m>1),每段绳子的长度记为k[0],k[1],...,k[m]。请问k[0]xk[1]x...xk[m]可能的最大乘积是多少?例如,当绳子的长度是8时,我们把它剪成长度分别为2、3、3的三段,此时得到的最大乘积是1 阅读全文
posted @ 2019-10-19 15:34 Sempron2800+ 阅读(122) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution: 2 def balancedStringSplit(self, s: str) -> int: 3 count,res = 0,0 4 for si in s: 5 if si == 'L': 6 count += 1 7 else: 8 count -= 1 9 if count == 0: 10 res += 1 11 return res 阅读全文
posted @ 2019-10-15 08:11 Sempron2800+ 阅读(217) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution: 2 def minCostToMoveChips(self, chips: List[int]) -> int: 3 n = len(chips) 4 odd,even = 0,0 5 for i in range(n): 6 cur = chips[i] 7 if cur % 2 == 0: 8 even += 1 9 else: 10 odd += 1 11 阅读全文
posted @ 2019-10-06 13:44 Sempron2800+ 阅读(180) 评论(0) 推荐(0) 编辑
摘要: 两次遍历,第一次先计算A,如果对应位置的字符一样,则A+1;如果对应位置的字符不同,则分别计算两个串不匹配字符的数量。 第二次计算B,在不匹配的字符中,两个字典都出现的,就符合B,其值为这个字符在两个字典中的值较小的。 阅读全文
posted @ 2019-10-04 16:06 Sempron2800+ 阅读(125) 评论(0) 推荐(0) 编辑
上一页 1 ··· 41 42 43 44 45 46 47 48 49 ··· 114 下一页