發表文章

目前顯示的是 12月, 2019的文章

[ Leetcode ] 31. Next Permutation

圖片
Implement  next permutation , which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possible, it must rearrange it as the lowest possible order (ie, sorted in ascending order). The replacement must be  in-place  and use only constant extra memory. Here are some examples. Inputs are in the left-hand column and its corresponding outputs are in the right-hand column. 1,2,3  →  1,3,2 3,2,1  →  1,2,3 1,1,5  →  1,5,1 class Solution(object):     def nextPermutation(self, nums):         """         :type nums: List[int]         :rtype: None Do not return anything, modify nums in-place instead.         """         if not nums:             return nums                  first,...

[ Leetcode ] 456. 132 Pattern

圖片
456 .  132 Pattern one -> three -> twp patten - assume every number in the iteration is three. - use three to find the max two - if you find the two and three, and now there's a number small than two. then you got it. class Solution(object):     def find132pattern(self, nums):         """         :type nums: List[int]         :rtype: bool         """         st = []         two = float('-inf')         # assume every number in the iteration is three.         for i in range(len(nums) - 1, -1, -1):                          # if you find the two and three, and now there's a number small than two. then you got it.             if nums[i] < two:       ...