diff --git "a/14_\345\210\267\351\242\230/day03/problem_solving_18_01.py" "b/14_\345\210\267\351\242\230/day02/problem_solving_18_01.py" similarity index 100% rename from "14_\345\210\267\351\242\230/day03/problem_solving_18_01.py" rename to "14_\345\210\267\351\242\230/day02/problem_solving_18_01.py" diff --git "a/14_\345\210\267\351\242\230/day03/problem_solving_18_02.py" "b/14_\345\210\267\351\242\230/day02/problem_solving_18_02.py" similarity index 100% rename from "14_\345\210\267\351\242\230/day03/problem_solving_18_02.py" rename to "14_\345\210\267\351\242\230/day02/problem_solving_18_02.py" diff --git "a/14_\345\210\267\351\242\230/day03/problem_solving_19_01.py" "b/14_\345\210\267\351\242\230/day02/problem_solving_19_01.py" similarity index 100% rename from "14_\345\210\267\351\242\230/day03/problem_solving_19_01.py" rename to "14_\345\210\267\351\242\230/day02/problem_solving_19_01.py" diff --git "a/14_\345\210\267\351\242\230/day03/problem_solving_19_02.py" "b/14_\345\210\267\351\242\230/day02/problem_solving_19_02.py" similarity index 100% rename from "14_\345\210\267\351\242\230/day03/problem_solving_19_02.py" rename to "14_\345\210\267\351\242\230/day02/problem_solving_19_02.py" diff --git "a/14_\345\210\267\351\242\230/day03/problem_solving_19_03.py" "b/14_\345\210\267\351\242\230/day02/problem_solving_19_03.py" similarity index 100% rename from "14_\345\210\267\351\242\230/day03/problem_solving_19_03.py" rename to "14_\345\210\267\351\242\230/day02/problem_solving_19_03.py" diff --git "a/14_\345\210\267\351\242\230/day03/problem_solving_20.py" "b/14_\345\210\267\351\242\230/day02/problem_solving_20.py" similarity index 100% rename from "14_\345\210\267\351\242\230/day03/problem_solving_20.py" rename to "14_\345\210\267\351\242\230/day02/problem_solving_20.py" diff --git "a/14_\345\210\267\351\242\230/day03/problem_solving_25.py" "b/14_\345\210\267\351\242\230/day03/problem_solving_25.py" new file mode 100644 index 0000000000000000000000000000000000000000..b7ea5cd58422d16a5f1257dc139bf8051c92cc86 --- /dev/null +++ "b/14_\345\210\267\351\242\230/day03/problem_solving_25.py" @@ -0,0 +1,27 @@ +""" +最大连续 1 的个数 +""" +from typing import List + + +class Solution: + def findMaxConsecutiveOnes(self, nums: List[int]) -> int: + """ + 试试贪心算法 + :param nums: + :return: + """ + res = 0 + count = 0 + for num in nums: + if num == 0: + count = 0 + continue + count += 1 + res = max(res, count) + return res + + +if __name__ == '__main__': + result = Solution().findMaxConsecutiveOnes([1, 1, 0, 1, 1, 1]) + print(result) diff --git "a/14_\345\210\267\351\242\230/day03/problem_solving_26.py" "b/14_\345\210\267\351\242\230/day03/problem_solving_26.py" new file mode 100644 index 0000000000000000000000000000000000000000..262cd5399836b49d74c7decc2152898d029c39f0 --- /dev/null +++ "b/14_\345\210\267\351\242\230/day03/problem_solving_26.py" @@ -0,0 +1,27 @@ +""" +提莫攻击 +""" +from typing import List + + +class Solution: + def findPoisonedDuration(self, timeSeries: List[int], duration: int) -> int: + """ + 贪心算法 + :param timeSeries: + :param duration: + :return: + """ + if not timeSeries: + return 0 + res = duration + for i in range(1, len(timeSeries)): + # 中毒时间取最小值,当有重叠时timeSeries[i] - timeSeries[i - 1] + res += min(duration, timeSeries[i] - timeSeries[i - 1]) + return res + + +if __name__ == '__main__': + # result = Solution().findPoisonedDuration([1, 4], 2) + result = Solution().findPoisonedDuration([1, 2], 2) # 输出3 + print(result)