题目 Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct. Subscribe to see which companies ask…
题目: Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between i and jis at most k. 给定一个整形数组和一个整数型数k,找出在这个数组中是否存在两个相同的数,并且这两个数的下标的距离小于k. "&q…
题目: Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and return its area. For example, given the following matrix: 1 0 1 0 0 1 0 1 1 1 1 1 0 0 1 0 Return 4. 本题为一个典型的动态规划问题,因此可以使用动态规划的思想进行. step1,初始化原始行和列 st…
题目: Given an integer, write a function to determine if it is a power of two. class Solution(object): def isPowerOfTwo(self, n): # """ :type n: int :rtype: bool """ 方法:分析2的幂次方的特点,发现2的任意次方的数,化成二进制时只有首位为1其余位为0,因此我的解决方法如下: class…
Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the absolute difference between i and j is at most k. Example 1: Input: nums = [1,2,3,1], k = 3 Output:…
Given an array of integers, find out whether there are two distinct indices i and j in the array such that the absolute difference between nums[i] and nums[j] is at most t and the absolute difference between i and j is at most k. Example 1: Input: nu…
2017/11/3 Leetcode 日记 654. Maximum Binary Tree Given an integer array with no duplicates. A maximum tree building on this array is defined as follow: The root is the maximum number in the array.(根节点是数组中的最大值) The left subtree is the maximum tree const…
知识回顾 在上一周的学习里,我学习了一些学习Python的基础知识下面先简短的回顾一些: 1Python的版本和和安装 Python的版本主要有2.x和3.x两个版本这两个版本在语法等方面有一定的区别.在安装的的时候需要注意.剩下的就是在官网选择适合自己操作系统版本的Python安装即可 2Python的内容编码 接下来就有关Python的内容编码的问题 .Python2.x默认是acsll编码.因此不支持中文.Python 3 则不存在这个问题 因此在Python2.x环境中需要在代码的开始加…
Python学习日记 --day2 1.格式化输出:% s d  (%为占位符 s为字符串类型 d为数字类型) name = input('请输入姓名') age = int(input('请输入年龄')) height = input('请输入身高') job = input('请输入工作') hobbie = input('我的爱好是') msg = '''-------info of %s -------- 姓名: %s 年龄: %d 身高: %s 工作: %s 爱好: %s ------…
数字 int 主要是用于计算的,常用的方法有一种 #既十进制数值用二进制表示时,最少使用的位数i = 3#3的ASCII为:0000 0011,即两位 s = i.bit_length() print(s) 布尔值 bool  True/False while True: 等价于: while 1:   ###较简便 while 1: print('all trule') 字符串 str 字符串的索引与切片 索引:索引既下标,字符串元素从第一个开始,初始索引为0.以此类推. s = 'sdfjs…