Commit fddb87fe by yangpengflag

init commit

parents
'''
链表至少包含两个节点。
链表中所有节点的值都是唯一的。
给定的节点为非末尾节点并且一定是链表中的一个有效节点。
不要从你的函数中返回任何结果。
'''
class Solution:
def deleteNode(self, node):
"""
:type node: ListNode
:rtype: void Do not return anything, modify node in-place instead.
输入: head = [4,5,1,9], node = 5
输出: [4,1,9]
"""
if node == None:
return node
if node.next == None:
node = None
node.val = node.next.val
node.next = node.next.next
# temp = []
# for i in range(len(head)):
# if head[i] == node:
# continue
# else:
# temp.append(head[i])
# return temp
#
#
# head = [4,5,1,9]
# node = 5
#
# print(deleteNode(head,node))
import os
import shutil
import logging
# 实现图片文件的复制
'''
定义一个函数,接受两个参数,第一个参数是原始图片文件,第二个参数是复制到的路径
'''
def copy_image(source_file,target_path):
if not os.path.exists(target_path):
os.makedirs(target_path)
if os.path.exists(source_file):
# shutil.copy(r'要复制的文件路径(路径+文件)',r'复制到的路径') bits模式
shutil.copy(source_file, target_path)
# shutil.copyfileobj(open(source_file, 'rb'), open(target_path, 'wb'))
print(source_file)
print(target_path)
"""
这里要考虑,给定的参数file_path是文件还是文件夹,如果是文件则直接列出来文件名称就可以
如果是文件夹,那么要列出这个文件夹下所有的文件名称,同时要考虑,文件夹下是否还有文件夹
直到保证此文件夹下再不包含文件夹,列出所有的文件名称即可
# 每当读取一个文件夹时,打一个info级别的log,标记开始读取哪个文件夹
"""
def get_files(file_path):
if not os.path.exists(file_path):
logging.warning("地址不存在,请检查")
if os.path.isfile(file_path):
print(file_path[0:file_path.find("\\|/")])
return file_path
if os.path.isdir(file_path):
print("该地址是文件夹")
files = os.listdir(file_path)
for i in range(len(files)):
logging.info("开始读取文件夹%s" %files[i])
print("开始读取文件夹%s" %files[i])
filelist = os.path.join(file_path,files[i])
if len(filelist) > 0:
get_files(os.path.abspath(filelist))
print("文件读取完毕")
'''
从一个目录将全部文件(包含子目录)copy到另外一个目录,只copy文件,不操作文件夹
'''
def copy_dir_2_dir(source_path,target_path):
if not os.path.exists(target_path):
os.makedirs(target_path)
if os.path.exists(source_path):
# root 所指的是当前正在遍历的这个文件夹的本身的地址
# dirs 是一个 list,内容是该文件夹中所有的目录的名字(不包括子目录)
# files 同样是 list, 内容是该文件夹中所有的文件(不包括子目录,只copy子目录中的文件,目录结构不copy)
for root, dirs, files in os.walk(source_path):
print("root:%s" % root)
print("dirs:%s" % dirs)
print("files:%s" % files)
for file in files:
src_file = os.path.join(root, file)
shutil.copy(src_file, target_path)
print(src_file)
print('copy files finished!')
# copy图片
# copy_image("D:/wechaticon.png","D:/test1/")
#
# # copy视频
# copy_image("D:/珠宝展示网站用视频新版_x264.mp4","D:/test1/")
# get_files("D:\\wechaticon.png")
# get_files("D:\\test1")
copy_dir_2_dir("D:\\壁纸","D:\\test1")
\ No newline at end of file
# 指定日志输出目标文件的文件名,指定该设置项后日志信心就不会被输出到控制台了
filename = aitest.log
# 指定日志器的日志级别
level = DEBUG
# 指定日志格式字符串,即指定日志输出时所包含的字段信息以及它们的顺序
format = %(asctime)s - %(levelname)s - %(message)s
# 指定日期/时间格式。需要注意的是,该选项要在format中包含时间字段%(asctime)s时才有效
datefmt = %Y/%m/%d %H:%M:%S
\ No newline at end of file
class Properties():
def __init__(self,filename):
self.properties_file_name = filename
self.properties = {}
def get_properties(self) ->dict:
with open(self.properties_file_name,'r',encoding="UTF-8") as pro_file:
for line in pro_file.readlines():
line = line.strip().replace("\n","")
if line.find("#") != -1:
line = line[0:line.find("#")]
if line.find("=") > 0:
strs = line.split("=")
self.__get_dit(strs[0].strip(),self.properties,strs[1].strip())
return self.properties
def __get_dit(self, key_name, result_dict, key_value):
if (key_name.find(".") > 0):
k = key_name.split(".")[0]
result_dict.setdefault(k, {})
return self.__get_dit(key_name[(len(k)+1):], result_dict(k), key_value)
else:
result_dict[key_name] = key_value
from loggerutils.logger_properties import Properties
import logging
def set_log_config():
log_config = Properties('log.properties').get_properties()
logging.basicConfig(**log_config)
logging.debug("debug ******")
\ No newline at end of file
'''
你和你的朋友,两个人一起玩 Nim游戏:桌子上有一堆石头,每次你们轮流拿掉 1 - 3 块石头。 拿掉最后一块石头的人就是获胜者。你作为先手。
你们是聪明人,每一步都是最优解。 编写一个函数,来判断你是否可以在给定石头数量的情况下赢得游戏。
示例:
输入: 4
输出: false
解释: 如果堆中有 4 块石头,那么你永远不会赢得比赛;
因为无论你拿走 1 块、2 块 还是 3 块石头,最后一块石头总是会被你的朋友拿走。
'''
def nim_game_by_recursive(stone_num):
if stone_num <= 0:
print("请输入大于0的整数")
return False
# 当轮到你拿时剩余的石块大于0小于4,你讲获胜
if stone_num > 0 and stone_num < 4 :
return True
# 使用递归判断,但是数字大的时候可能会出现递归太深的问题
return not(nim_game_by_recursive(stone_num-1) & nim_game_by_recursive(stone_num-2) & nim_game_by_recursive(stone_num-3))
print(nim_game_by_recursive(16))
print(nim_game_by_recursive(8))
print(nim_game_by_recursive(4))
print(nim_game_by_recursive(20))
print(nim_game_by_recursive(5))
print(nim_game_by_recursive(6))
print(nim_game_by_recursive(7))
#发现一个规律,只要被4整除都不可能赢。。。。
def nim_game(stone_num):
if stone_num % 4 != 0:
return True
else:
return False
print(nim_game(1))
print(nim_game(2))
print(nim_game(3))
print(nim_game(4))
print(nim_game(5))
print(nim_game(6))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment