摘要: Python内置的os模块也可以直接调用操作系统提供的接口函数。 os.listdir()可以列出给定目录下的文件和下级目录 os.path.isfile()方法可以验证该文件是否真的存在,注意这里需要完整路径或者相对当前目录下的相对路径. 阅读全文
posted @ 2018-10-18 14:16 slarker 阅读(4711) 评论(0) 推荐(0) 编辑
摘要: Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. k is a positive integer and is less than or equal to 阅读全文
posted @ 2018-10-09 13:36 slarker 阅读(478) 评论(0) 推荐(0) 编辑
摘要: Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. Example: 阅读全文
posted @ 2018-10-09 13:32 slarker 阅读(382) 评论(0) 推荐(0) 编辑
摘要: 原题: Given a linked list, swap every two adjacent nodes and return its head. Example: Given 1->2->3->4, you should return the list as 2->1->4->3. Note: 阅读全文
posted @ 2018-09-26 16:21 slarker 阅读(350) 评论(0) 推荐(0) 编辑
摘要: 这三个题目基本属于同一类型,这里我的解题思路是所谓的‘夹逼定理’。不同的题目运用该思路会有一点区别,总体上是大同小异。 先来看15题: 题目要求取出数列中可以加起来为0的三个数来组成序列并添加到新的序列中去。这个题目其实非常简单,和之前水桶装水的题目有些类似。这里只需要先绑定两端,中间的值动。 16 阅读全文
posted @ 2018-09-16 22:51 slarker 阅读(341) 评论(0) 推荐(0) 编辑
摘要: 题目: Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. A mapping of digit t 阅读全文
posted @ 2018-09-03 18:12 slarker 阅读(987) 评论(0) 推荐(0) 编辑
摘要: LeetCode第十一题 Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that 阅读全文
posted @ 2018-08-24 22:51 slarker 阅读(340) 评论(0) 推荐(0) 编辑
摘要: 英文题目:The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed 阅读全文
posted @ 2018-08-23 17:02 slarker 阅读(722) 评论(0) 推荐(0) 编辑
摘要: 最近刷leetcode遇到分行取字符串再重新拼接的题目,解题过程中使用了动态生成变量的相关办法。后来发现用字典更加简单。 动态生成如下: 其中运用了locals()来返回变量。 这个方法其实很一般,如果运用迭代来生成字典则非常简单。 附动态生成变量与字典的截图代码对比: 字典显得简洁的多,更适合py 阅读全文
posted @ 2018-08-23 16:48 slarker 阅读(5412) 评论(0) 推荐(0) 编辑