自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(9)
  • 收藏
  • 关注

原创 Task8(简单)位运算:169.求众数

class Solution:def majorityElement(self, nums):majority_count = len(nums)//2for num in nums:count = sum(1 for elem in nums if elem == num)if count > majority_count:return num

2019-08-13 20:05:22 530

原创 Task7位运算:136. 只出现一次的数字

class Solution(object):def singleNumber(self, nums):“”":type nums: List[int]:rtype: int“”"no_duplicate_list = []for i in nums:if i not in no_duplicate_list:no_duplicate_list.append(i)else:n...

2019-08-13 20:04:28 93

原创 Task6位运算:78.子集

class Solution:def subsets(self, nums: List[int]) -> List[List[int]]:res = []n = len(nums) def helper(i, tmp): res.append(tmp) for j in range(i, n): helper(j + 1,...

2019-08-13 20:03:23 79

原创 task5排序148.排序链

class Solution:def sortList(self, head: ListNode) -> ListNode:if not head or not head.next: return head # termination.# cut the LinkedList at the mid index.slow, fast = head, head.nextwhile fa...

2019-08-13 20:01:59 102

原创 Leecode day4——贪心算法

class Solution:def maxProfit(self, prices: List[int]) -> int:sum=0for i in range(1,len(prices)):temp=prices[i]-prices[i-1]if temp>0:sum+=tempreturn sum

2019-08-09 20:33:22 156

原创 4、合并K个排序链表

class Solution(object):def mergeKLists(self, lists):“”":type lists: List[ListNode]:rtype: ListNode“”"self.nodes = []head = point = ListNode(0)for l in lists:while l:self.nodes.append(l.val)...

2019-08-07 19:37:19 94

原创 3、数组中的第K个最大元素

class Solution:def findKthLargest(self, nums, k,):k=2nums.sort()return nums[len(nums)-k]

2019-08-06 19:39:23 103

原创 2、有效的括号

class Solution:def isValid(self, s: str):while “{}” in s or “()” in s or “[]“in s:s=s.replace(”{}”," “)s=s.replace(”()"," “)s=s.replace(”[]"," “)return s ==” "

2019-08-05 19:38:46 77

原创 1、最小栈

最小栈class MinStack:def __init__(self): """ initialize your data structure here. """ self.data=[] self.helper=[] def push(self, x: int): self.data.append(x) if len(se...

2019-08-04 17:35:42 71

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除