20. 有效括号  48ms

class Solution:def isValid(self, s):""":type s: str:rtype: bool"""if len(s) % 2 :return Falsebrackets = {'(': ')', '{': '}', '[': ']'}stack = []for i in s:if i in brackets:stack.append(i)else:if not stack or brackets[stack.pop()] != i:return Falseif stack:return Falsereturn True

26.删除排序数组中的重复项  96ms

class Solution:def removeDuplicates(self, nums):""":type nums: List[int]:rtype: int"""if len(nums) <= 1:return len(nums)s = 0for f in range(1, len(nums)):if nums[s] != nums[f]:s += 1nums[s] = nums[f]return s + 1

27.移除元素  56ms

class Solution:def removeElement(self, nums, val):""":type nums: List[int]:type val: int:rtype: int"""if val not in nums:return len(nums)while val in nums:nums.remove(val)return len(nums)

28.实现strStr()  48ms

class Solution:def strStr(self, haystack, needle):""":type haystack: str:type needle: str:rtype: int"""if not needle:return 0if needle not in haystack:return -1else:return haystack.index(needle)

35.搜索插入位置  48ms

class Solution:def searchInsert(self, nums, target):""":type nums: List[int]:type target: int:rtype: int"""if target in nums:return nums.index(target)if target < nums[0]:return 0if target > nums[-1]:return len(nums)for i in range(len(nums)-1):if nums[i]<target and nums[i+1]>target:return i+1

转载于:https://www.cnblogs.com/FanMLei/p/10501003.html

Leet Code OJ 简单(二)相关推荐

  1. Leet Code OJ 119. Pascal's Triangle II [Difficulty: Easy]

    题目: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return ...

  2. Leet Code OJ 刷题顺序参考

    出现频度为5:  1. Leet Code OJ 1. Two Sum [Difficulty: Easy]  2. Leet Code OJ 8. String to Integer (atoi) ...

  3. Leet Code OJ 110. Balanced Binary Tree [Difficulty: Easy]

    题目: Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced bin ...

  4. Leet Code OJ 223. Rectangle Area [Difficulty: Easy]

    题目: Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defin ...

  5. Leet Code OJ 206. Reverse Linked List [Difficulty: Easy]

    题目: Reverse a singly linked list. Hint: A linked list can be reversed either iteratively or recursiv ...

  6. Leet Code OJ 7. Reverse Integer [Difficulty: Easy]

    题目: Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 Have ...

  7. Leet Code OJ 38. Count and Say [Difficulty: Easy]

    题目: The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 11 ...

  8. Leet Code OJ 112. Path Sum [Difficulty: Easy]

    题目: Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up ...

  9. Leet Code OJ 292. Nim Game [Difficulty: Easy]

    题目: You are playing the following Nim Game with your friend: There is a heap of stones on the table, ...

最新文章

  1. hibernate fetch使用
  2. IntelliJ IDEA 重大更新:支持CPU火焰图,新增酷炫主题
  3. .NET速度的问题,不是最重要的
  4. boost::type_erasure::ostreamable相关的测试程序
  5. Oracle Solaris 11 Express发布了
  6. matlab save txt 乱码,matlab代码或中文复制到word就变成乱码怎么办?
  7. oracle客户端三种连接,客户端连接ORACLE的几种方法
  8. Inject Dll 过程
  9. 深入理解JVM虚拟机(总结篇)
  10. S-MAC协议的相关知识
  11. three.js实现世界3d地图
  12. IT界有哪些书是必看的?
  13. 吾爱破解新手教程(1)- 破解,逆向,安全
  14. 幻云蜜网筑迷阵 春秋靶场信安大赛从攻击者角度看安全
  15. 如何选择最适合的房屋贷款方式
  16. 微信自媒体账号涉违规大规模被封
  17. 太赞了!Python 开发神器Jupyter竟然还有可视化debug功能!
  18. 120行代码爬取电子书网站
  19. MD5 转码 实现加密解密
  20. Java连接Mysql数据库详细步骤(超级详细)

热门文章

  1. Swift学习--常量.变量.数据类型的使用(一)
  2. 【问题收集·中级】关于XMPP使用Base传送图片
  3. 获取当前目录所有文件名 并且保存为1个00000.txt的文件文件bat
  4. JSON asp(vbs)中文支持问题
  5. 如何使用Hadoop的JobControl
  6. 编写多线程Java应用程序常见问题
  7. qt combox 向上弹出_一睹芳容!人类首次拍到活的公羊角乌贼 手臂和触须向上飞速穿过水柱...
  8. UVA10047独轮车
  9. 【C 语言】指针数据类型 ( 指针类型变量 | 使用 * 操作内存 )
  10. 【OkHttp】OkHttp 源码分析 ( 网络框架封装 | OkHttp 4 迁移 | OkHttp 建造者模式 )