- 博客(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 543
原创 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 119
原创 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 112
原创 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 132
原创 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 191
原创 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 123
原创 3、数组中的第K个最大元素
class Solution:def findKthLargest(self, nums, k,):k=2nums.sort()return nums[len(nums)-k]
2019-08-06 19:39:23 113
原创 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 86
原创 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 83
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人