01 2017 档案
摘要:Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in or
阅读全文
摘要:Given an array of integers sorted in ascending order, find the starting and ending position of a given target value. Your algorithm's runtime complexi
阅读全文
摘要:Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). You a
阅读全文
摘要:Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring. For "(()", the lo
阅读全文
摘要:合并k个已合并链表。 思路:先把链表两两合并,直到合并至只有一个链表
阅读全文
摘要:I thought I know Python... Actually , I know nothing... 这个题真想让人背下来啊,每一句都很帅!!! Given n pairs of parentheses, write a function to generate all combinati
阅读全文
摘要:There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity sh
阅读全文
摘要:Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. Example: Example: 题意:求最长回文串。 思路:我是
阅读全文
摘要:Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be partially filled, where empty cells are filled wit
阅读全文
摘要:Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possib
阅读全文
摘要:You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a conca
阅读全文
摘要: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
阅读全文
摘要:题意:不用乘除求余运算,计算除法,溢出返回INT_MAX。 首先考虑边界条件,什么条件下会产生溢出?只有一种情况,即返回值为INT_MAX+1的时候。 不用乘除求余怎么做? 一.利用减法。 耗时太长,如果被除数是INT_MIN,除数是1的时候,要循环-INT_MIN次 二.利用位运算 思路来自:ht
阅读全文
摘要:遍历一段文字,统计每个字后面出现的字和其次数,当前一个字确定的时候,计算后一个字出现的百分比,用这个百分比作为文字生成器中后一个字出现的概率进行文字生成 这是利用《百年孤独》第一章的文字作为来源,生成的结果 ——————————————————————————————————————————————
阅读全文
摘要:再Python中是利用引用计数来实现对象管理和垃圾回收的,即其他对象引用该对象时候,其引用计数加1,反之减1,当引用计数为0时候,被垃圾收集器回收。 Python解释器对对象以及计数器的管理分为以下两步: 1)其引用计数减1 2)判断引用计数是否为0,为0的话,销毁对象 因为使用引用计数,造成两个问
阅读全文
摘要:协程的实现为协作式而非抢占式的,这是和进程线程的最大区别。在Python中,利用yield和send可以很容易实现协程。 首先复习下生成器。 如果一个函数使用了yield语句,那么它就是一个生成器函数。当调用这个函数时,它返回一个迭代器。当第一次调用__next__()时候,生成器函数主体开始执行,
阅读全文
摘要:0/1背包问题:在能承受一定重量的背包中,放入重量不同,价值不同的几件物品,怎样放能让背包中物品的价值最大? 比如,有三件物品重量w,价值v分别是 w=[5,3,2] v=[9,7,8] 包的容量是5,也就是我们要求得 maxVal=v1+v2+v3…… 约束条件为:ws=w1+w2+w3…… 我们
阅读全文

浙公网安备 33010602011771号