类似于字符串的匹配,我们总是找到第一个匹配的字符,在继续比较以后的字符是否全部相同,如果匹配串的第一个字符与模式串的第一个不相同,我们就去查看匹配串的下一个字符是否与模式串的第一个相同,对应到这里,就是我们要遍历root1,找到与root2相同的第一个结点,若root1的根不相同,那么我们查找其左子树是否有第一个相同的,相同的操作再去看右子树是否有相同的第一个,若找到了第一个相同的,与字符串匹配思...
分类:
其他好文 时间:
2014-07-08 20:43:26
阅读次数:
216
def Merge(head1, head2):
if head1 == None: return head2
if head2 == None: return head1
psuhead = ListNode(-1)
tail = psuhead
while head1 and head2:
if head1.val < head2.val:
cur = head1
...
分类:
其他好文 时间:
2014-07-08 18:46:04
阅读次数:
227
Services aredistinguished into categories defined in [7]; also the categorisation of cellsaccording to services they can offer is provided in [7].
- Normal Service. A UE camped on a suitable cell...
分类:
其他好文 时间:
2014-07-08 18:18:03
阅读次数:
171
def Fibonacci(n):
if n <= 0:
return 0
if n <= 1:
return n
f0 = 0; f1 = 1
for i in range(2, n + 1):
fn = f0 + f1
f0 = f1
f1 = fn
return fn...
分类:
其他好文 时间:
2014-07-08 16:42:03
阅读次数:
163
def FirstNotRepeatingChar(string):
hashStr = [0] * 256
for c in string:
hashStr[ord(c)] += 1
for c in string:
if hashStr[ord(c)] == 1:
return c
这里说下ord, 可以作为atoi来用,功能是若给定的参数是一个长度为1的字符串,那么若...
分类:
其他好文 时间:
2014-07-08 16:15:10
阅读次数:
183
pow(base, exponent)
考虑一下几种情况:
base = 0, 那么直接返回0
base = 1, 那么直接返回1
exponent = 0, 那么直接返回1, 注意base= 0
exponent = 1, 那么直接返回 base
exponent 为正为负 的情况
主要考察的点是将问题缩减,用折半的思想。这个题细节还是很多的,为了便于验证,leetcode上恰好...
分类:
其他好文 时间:
2014-07-08 15:32:43
阅读次数:
157
def reverse(head):
if head == None or head.next == None:
return head
psuhead = ListNode(-1)
while head:
nexthead = head.next
head.next = psuhead.next
psuhead.next = head
head = nexthead
...
分类:
其他好文 时间:
2014-07-08 15:27:58
阅读次数:
183
def MirroRecursively(root):
# root is None or just one node, return root
if None == root or None == root.left and None == root.right:
return root
root.left, root.right = root.right, root.left
Mi...
分类:
其他好文 时间:
2014-07-08 14:26:08
阅读次数:
221
通常我们所说的删除链表的某个结点,是彻底删除该结点的空间,而要这么做就必须知道其前驱结点。这里的想法是,链表中存储的val是同类型的,只要将该结点的val内容删除就可以了。那么就可以用该结点的后继结点的值覆盖当前结点,然后删除其后继结点,而对于其后继结点而言,该结点就是前驱。
这里只需要考虑当前删除的结点是否为last node 就可以了,至于是否是头结点,这种情况是可以归为同一种情况的,只是参...
分类:
其他好文 时间:
2014-07-08 13:58:04
阅读次数:
197
def isOdd(n):
return n & 1
def Reorder(data, cf = isOdd):
odd = 0
even = len( data ) - 1
while True:
while not isOdd( data[ even ]) : even -= 1
while isOdd( data[ odd ]) : odd += 1
if odd ...
分类:
其他好文 时间:
2014-07-08 12:47:26
阅读次数:
276