数据结构与算法
文章平均质量分 66
KayGuoWhu
Less speaking, more coding
展开
-
时间复杂度和空间复杂度
没有挤公交来上班过,就不知道生活的压力有多大。 算法的时间复杂度和空间复杂度合称为算法的复杂度。 1.时间复杂度 (1)时间频度 一个算法执行所耗费的时间,从理论上是不能算出来的,必须上机运行测试才能知道。但我们不可能也没有必要对每个算法都上机测试,只需知道哪个算法花费的时间多,哪个算法花费的时间少就可以了。并且一个算法花费的时间与算法中语句的执行次数成正比例,哪个算法中转载 2012-11-09 19:53:27 · 1117 阅读 · 0 评论 -
【LeetCode刷题记录】H-Index
题目Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher’s h-index.According to the definition of h-index on Wikipedia: “A sci原创 2015-10-18 20:47:07 · 646 阅读 · 0 评论 -
【LeetCode刷题记录】LRU Cache
题目Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set.get(key) - Get the value (will always be positive) of the key if the原创 2015-10-16 13:38:06 · 575 阅读 · 0 评论 -
【LeetCode刷题记录】Two Sum
题目Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target, where原创 2015-05-21 09:29:56 · 610 阅读 · 0 评论 -
【LeetCode刷题记录】Reverse Integer
题目Reverse digits of an integer.Example1: x = 123, return 321 Example2: x = -123, return -321Here are some good questions to ask before coding. Bonus points for you if you have already thought through原创 2015-05-07 21:49:54 · 560 阅读 · 0 评论 -
【LeetCode刷题记录】Reverse Bits
题目Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 001110010111原创 2015-05-06 22:02:19 · 583 阅读 · 0 评论 -
【LeetCode刷题记录】Pascal's Triangle
题目:Given numRows, generate the first numRows of Pascal’s triangle.For example, given numRows = 5, Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ]解答:帕斯卡三角,又名“杨辉三角”,基本规律是每一行的第原创 2015-04-25 18:01:42 · 615 阅读 · 1 评论 -
【LeetCode刷题记录】Rotate Array
LeetCode数组题之Rotate Array原创 2015-04-14 08:30:40 · 552 阅读 · 0 评论 -
【LeetCode刷题记录】Merge Sorted Array
题目:Merge Sorted Array Given two sorted integer arrays A and B, merge B into A as one sorted array. Note: You may assume that A has enough space (size that is greater or equal to m + n) to hold a原创 2015-04-15 08:30:42 · 568 阅读 · 0 评论 -
【LeetCode刷题记录】Pascal's Triangle II
题目Given an index k, return the kth row of the Pascal’s triangle.For example, given k = 3, Return [1,3,3,1].Note: Could you optimize your algorithm to use only O(k) extra space?解答这题和Pascal Triangle相近,原创 2015-04-26 22:08:11 · 562 阅读 · 0 评论 -
【LeetCode刷题记录】Single Number
题目一: Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without u原创 2015-04-16 22:43:14 · 584 阅读 · 0 评论 -
【LeetCode刷题记录】Number of 1 Bits
题目: Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight). For example, the 32-bit integer ’11' has binary representation 000原创 2015-04-20 08:54:23 · 535 阅读 · 0 评论 -
快速模取幂算法
快速模取幂 数论计算中经常出现的一种运算就是求一个数的幂ab对另外一个数n个模的运算,即计算: ab mod n (a,b,n是正整数) 由于计算机只能表示有限位的整数,所以编程时模取幂的运算要注意值的大小范围,当ab的值超过整数范围时,mod运算便无法进行。 如何解决这个问题,我们引出一个能计算ab mod n的值的有用算法——反复平方法,首先我们转载 2012-10-24 16:14:57 · 882 阅读 · 0 评论 -
【LeetCode刷题记录】Integer to English Words
题目Convert a non-negative integer to its english words representation. Given input is guaranteed to be less than 231 - 1.For example, 123 -> “One Hundred Twenty Three” 12345 -> “Twelve Thousand Three原创 2015-10-12 22:23:27 · 680 阅读 · 0 评论