源式羽语

有志于学,不赞美,不责难,只求了解认识。

数组中查找给定值

def findk(m,k): if m is None: return False r = 0 c = len(m[0])-1 while r<len(m[0]) and c>=0 andc<len(m): ...

2018-05-01 21:31:52

阅读数:30

评论数:0

翻转单词顺序

思路:先翻转所有字符,再根据空格来翻转每个单词。解:1.写一个翻转函数       2.注意python 中字符串无法修改,要转为list,最后结果再转为str       3.遇到空格后要翻转单词,但注意翻转的下标,一不小心会把空格也翻转了。       4.左旋字符串也是一样的,只是分割不再用...

2018-04-12 17:44:42

阅读数:22

评论数:0

二叉树中和为给定值的所有路径

本质上是压栈出栈的过程1.写一个主题函数主题函数中要给定默认的树,给定的值,还要一个用来存路径的列表,再加一个记录路径长度的变量2.写一个找路径的函数首先要确定给的节点是不是一个空的,如果是空的则直接退出;其次,把当前节点加入到路径,把当前节点值加进路径长度然后,判断当前是不是叶子(叶子用一个变量...

2018-03-30 22:42:07

阅读数:38

评论数:0

python定义树

用python自定义树,先定义节点,然后在把节点合成树。class TreeNode(object): def __init__(self,root,left=None,right=None): self.root = root self.left = le...

2018-03-30 20:11:08

阅读数:319

评论数:0

119. Pascal's Triangle II

class Solution(object):     def getRow(self, rowIndex):         """         :type rowIndex: int         :rtype: List[int]        ...

2017-05-24 15:22:41

阅读数:94

评论数:0

118. Pascal's Triangle

class Solution(object):     def generate(self, numRows):         """         :type numRows: int         :rtype: List[List[int]]  ...

2017-05-24 15:04:28

阅读数:92

评论数:0

106Construct Binary Tree from Inorder and Postorder Traversal

# Definition for a binary tree node. # class TreeNode(object): #     def __init__(self, x): #         self.val = x #         self.left = None # ...

2017-05-24 12:30:57

阅读数:109

评论数:0

34. Search for a Range

class Solution(object):     def searchRange(self, nums, target):         """         :type nums: List[int]         :type target: i...

2017-05-19 11:34:23

阅读数:135

评论数:0

35. Search Insert Position

class Solution(object):     def searchInsert(self, nums, target):         """         :type nums: List[int]         :type target: ...

2017-05-19 10:10:16

阅读数:107

评论数:0

[leetcode 561]Array Partition I

题目:求2n个数字的数组组成n对中的每个小数字之和最大 nums.sort()         return sum(nums[::2])

2017-05-18 15:31:36

阅读数:129

评论数:0

[leetcode 560]Subarray Sum Equals K

题目:求连续子集和为k的个数代码出自:https://discuss.leetcode.com/topic/88041/super-simple-pythonclass Solution(object):    def subarraySum(self, nums, k):        &...

2017-05-18 15:13:18

阅读数:352

评论数:0

letcode153Find Minimum in Rotated Sorted Array

class Solution(object):     def findMin(self, nums):         """         :type nums: List[int]         :rtype: int         "...

2017-05-11 12:41:19

阅读数:106

评论数:0

[leetcode 53]Maximum Subarray

class Solution(object):     def maxSubArray(self, nums):         """         :type nums: List[int]         :rtype: int         &q...

2017-05-09 21:46:32

阅读数:95

评论数:0

[leetcode108]Convert Sorted Array to Binary Search Tree

# Definition for a binary tree node. # class TreeNode(object): #     def __init__(self, x): #         self.val = x #         self.left = None # ...

2017-05-09 21:14:45

阅读数:93

评论数:0

[leetcode 33]Search in Rotated Sorted Array

class Solution(object):     def search(self, nums, target):         """         :type nums: List[int]         :type target: int  ...

2017-05-09 11:08:26

阅读数:85

评论数:0

leetcode31Next Permutation

class Solution(object):     def nextPermutation(self, nums):         """         :type nums: List[int]         :rtype: void Do not...

2017-05-09 10:38:16

阅读数:82

评论数:0

[Leetcode 25] Reverse Nodes in k Group

# Definition for singly-linked list. # class ListNode(object): #     def __init__(self, x): #         self.val = x #         self.next = None ...

2017-05-08 19:53:06

阅读数:130

评论数:0

leetcode148 sort list

# Definition for singly-linked list. # class ListNode(object): #     def __init__(self, x): #         self.val = x #         self.next = None ...

2017-05-08 15:34:16

阅读数:93

评论数:0

leetcode83Remove Duplicates from Sorted List

# Definition for singly-linked list. # class ListNode(object): #     def __init__(self, x): #         self.val = x #         self.next = None class...

2017-05-05 20:33:55

阅读数:112

评论数:0

DFS学习

1.对于一个图,任意选一个节点作为起始节点 2.选择一个选择规则 3.走到有标记过的或者无法走的时候原路返回再走 特点:递归过程,二叉树的序列遍历

2017-04-25 17:21:47

阅读数:128

评论数:0

提示
确定要删除当前文章?
取消 删除
关闭
关闭