码迷,mamicode.com
首页 >  
搜索关键字:offer    ( 4910个结果
【剑指offer】Q18:树的子结构
类似于字符串的匹配,我们总是找到第一个匹配的字符,在继续比较以后的字符是否全部相同,如果匹配串的第一个字符与模式串的第一个不相同,我们就去查看匹配串的下一个字符是否与模式串的第一个相同,对应到这里,就是我们要遍历root1,找到与root2相同的第一个结点,若root1的根不相同,那么我们查找其左子树是否有第一个相同的,相同的操作再去看右子树是否有相同的第一个,若找到了第一个相同的,与字符串匹配思...
分类:其他好文   时间:2014-07-08 20:43:26    阅读次数:216
【剑指offer】Q17:合并两个排序的链表
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
待机状态下,服务类型 WCDMA Service type in Idle mode
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
【剑指offer】Q9:斐波那契数列
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
【剑指offer】第一个只出现一次的数
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
[剑指offer]Q11:数值的整数次方
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
【剑指offer】Q16:翻转链表
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
【剑指offer】Q19:二叉树的镜像
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
[剑指offer]Q13:O(1)时间删除链表的结点
通常我们所说的删除链表的某个结点,是彻底删除该结点的空间,而要这么做就必须知道其前驱结点。这里的想法是,链表中存储的val是同类型的,只要将该结点的val内容删除就可以了。那么就可以用该结点的后继结点的值覆盖当前结点,然后删除其后继结点,而对于其后继结点而言,该结点就是前驱。 这里只需要考虑当前删除的结点是否为last node 就可以了,至于是否是头结点,这种情况是可以归为同一种情况的,只是参...
分类:其他好文   时间:2014-07-08 13:58:04    阅读次数:197
【剑指offer】Q14:调整数组顺序使奇数位于偶数前面
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
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!