博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Leet Code OJ 简单(三)
阅读量:7101 次
发布时间:2019-06-28

本文共 1725 字,大约阅读时间需要 5 分钟。

58.最后一个单词的长度  52ms

class Solution:    def lengthOfLastWord(self, s):        """        :type s: str        :rtype: int        """        s = s.split(' ')        while "" in s:            s.remove("")        if not s:            return 0        return len(s[-1])

66.加一 56ms

class Solution:    def plusOne(self, digits):        """        :type digits: List[int]        :rtype: List[int]        """        sum = 0        r = []        for index, i in enumerate(digits):            sum += i*pow(10,len(digits)-index-1)        sum += 1        while sum:            i = 1            r.append(sum % pow(10,i))            sum = sum // pow(10,i)            i += 1        r.reverse()        return r

67.二进制求和 60ms

class Solution:    def addBinary(self, a, b):        """        :type a: str        :type b: str        :rtype: str        """        return (bin(int(a, 2) + int(b, 2))[2:])

69.x的平方根 76ms    击败了81.06% 的用户

class Solution:    def mySqrt(self, x):        """        :type x: int        :rtype: int        """        return int(pow(x, 0.5))

83.删除排序链表重复元素  76ms  击败了48.84% 的用户

# Definition for singly-linked list.# class ListNode:#     def __init__(self, x):#         self.val = x#         self.next = Noneclass Solution:    def deleteDuplicates(self, head):        """        :type head: ListNode        :rtype: ListNode        """        if not head:            return None        cur = head        while cur.next:            if cur.val == cur.next.val:                if cur.next.next:                    t = cur.next.next                    cur.next = t                else:                    cur.next = None            else:                cur = cur.next        return head

 

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

你可能感兴趣的文章
web 中的认证方式
查看>>
node模块之path——path.join和path.resolve的区别
查看>>
SDNU 1292.圣诞老人
查看>>
BZOJ 3629 约数和定理+搜索
查看>>
ClientDemo
查看>>
mysql
查看>>
命令行的快速入门【第一天】
查看>>
Xml 丶json丶 C/S KVO 数据库 SQL 数据持久化 复杂对象 集合视图综合
查看>>
开源监控系统整合Nagios+Cacti+Nconf详解
查看>>
对于深入响应式原理的深刻理解
查看>>
初级AD域渗透系列
查看>>
题解 P1036 【选数】
查看>>
【算法学习笔记】25.贪心法 均分纸牌问题的分析
查看>>
width:100vh有感而发
查看>>
模仿京东淘宝的物流跟踪模板样式
查看>>
我的Android进阶之旅------> Android为TextView组件中显示的文本添加背景色
查看>>
Leangoo新功能-卡片ID
查看>>
Java多线程概述
查看>>
网络编程之FTP服务端与客户端
查看>>
【渗透测试】如何利用burpsuite测试无回显漏洞
查看>>