摘要:
n^2 sort class Solution: """ @param a: an integer array @return: nothing """ def sort_integers1(self, a): # selection sort n = len(a) for i in range(n 阅读全文
摘要:
leap year: 1. 能被400整除的是闰年 2. 不能被100整除但能被4整除的是闰年 if a year is divisible by 4 and not divisible by 100 or divisible by 400,it is a leap year Given a yea 阅读全文
摘要:
python char to int: ord(character) int to char: chr(int_num) Convert a lowercase character to uppercase. Example 1: Input: 'a' Output: 'A' Example 2: 阅读全文
摘要:
class Solution: """ @param a: An integer @param b: An integer @return: The sum of a and b """ def aplusb(self, a, b): # write your code here if b == 0 阅读全文
摘要:
Two sum 两数之和 https://leetcode.cn/problems/two-sum/ class Solution: """ @param numbers: An array of Integer @param target: target = numbers[index1] + n 阅读全文
摘要:
315. 计算右侧小于当前元素的个数 给定一个整数数组 nums,按要求返回一个新数组 counts。数组 counts 有该性质: counts[i] 的值是 nums[i] 右侧小于 nums[i] 的元素的数量。 示例: 输入: [5,2,6,1] 输出: [2,1,1,0] 解释: 5 的右 阅读全文
摘要:
1. quickSort 1 import random 2 class Solution: 3 def partition(self,nums,left,right): 4 idx=random.randint(left,right) # 闭区间 5 pivot=nums[idx] 6 7 num 阅读全文
摘要:
410 分割数组的最小值 1 class Solution(object): 2 def splitArray(self, nums, m): 3 """ 4 :type nums: List[int] 5 :type m: int 6 :rtype: int 7 """ 8 9 n=len(num 阅读全文
摘要:
394. Decode String s = "3[a]2[bc]", return "aaabcbc". s = "3[a2[c]]", return "accaccacc". s = "2[abc]3[cd]ef", return "abcabccdcdcdef". 1 class Soluti 阅读全文
摘要:
当只有一个柱子需要涂色时,有k种可涂色方案; 当有两个柱子需要涂色时,有k(k-1)【diff】+k【same】种涂色方案; 当有三个柱子需要涂色时,有 (same+diff)*(k-1)【diff】+diff【same】种方案。 1 class Solution(object): 2 def nu 阅读全文