zoukankan      html  css  js  c++  java
  • leetcode-每日打卡-day 6

    leetcode 每日打卡

    those times when you get up early and you work hard; those times when you stay up late and you work hard; those times when don’t feel like working — you’re too tired, you don’t want to push yourself — but you do it anyway. That is actually the dream. That’s the dream. It’s not the destination, it’s the journey. And if you guys can understand that, what you’ll see happen is that you won’t accomplish your dreams, your dreams won’t come true, something greater will. mamba out


    那些你早出晚归付出的刻苦努力,你不想训练,当你觉的太累了但还是要咬牙坚持的时候,那就是在追逐梦想,不要在意终点有什么,要享受路途的过程,或许你不能成就梦想,但一定会有更伟大的事情随之而来。 mamba out~

    2020.2.13


    记录下来自己做题时得思路,并不一定是最优解

    面试题58 - II. 左旋转字符串

    class Solution:
        def reverseLeftWords(self, s: str, n: int) -> str:
            return s[n:len(s)]+s[:n]
    

    1108. IP 地址无效化

    解法一
    class Solution:
        def defangIPaddr(self, address: str) -> str:
            return address.replace('.','[.]')
    
    解法二
    class Solution:
        def defangIPaddr(self, address: str) -> str:
            ans = ''
            for i in address:
                if i == '.':
                    ans+='[.]'
                else:
                    ans += i
            return ans
    

    709. 转换成小写字母

    内置方法
    class Solution:
        def toLowerCase(self, str: str) -> str:
            return str.lower()
    
    class Solution:
        def toLowerCase(self, str: str) -> str:
            ans = ""
            for i in str:
                if i >= 'A' and i <= 'Z':
                    ans += chr(ord(i) + 32)
                else:
                    ans += i
            return ans
    

    面试题15. 二进制中1的个数

    class Solution:
        def hammingWeight(self, n: int) -> int:
            ans = 0
            while n > 0:
                ans += n & 1
                n = n >> 1
            return ans
    

    面试题 16.01. 交换数字

    class Solution:
        def swapNumbers(self, numbers: List[int]) -> List[int]:
            # 如何利用位运算交换两个数
            # swqp(a,b): 执行以下三步
            # a = a ^ b ; b = a ^ b;  a = a ^ b;
            numbers[0] = numbers[0] ^ numbers[1]
            numbers[1] = numbers[0] ^ numbers[1]
            numbers[0] = numbers[0] ^ numbers[1]
            return numbers
    
    
  • 相关阅读:
    OK335xS 网络连接打印信息 hacking
    OK335xS mac address hacking
    buildroot linux filesystem 初探
    busybox filesystem matrix-gui-2.0 undefined function json_encode()
    RPi 2B Documentation
    RPi 2B Raspbian SD卡内部架构
    Error building results for action sayHello in namespace /inteceptor
    linux 失败无连接 检查电缆吗
    Struts2
    struts2加入自定义的actionValidatorManager实现类
  • 原文地址:https://www.cnblogs.com/wlw-x/p/12305666.html
Copyright © 2011-2022 走看看