- 博客(242)
- 收藏
- 关注
原创 <<模式识别与机器学习 (Pattern Recognization and Maching Learning)>>(PRML) 总结
\quadBishop 的大作《模式识别与机器学习》(Pattern Recognization and Maching Learning),简称为PRML,这本书被认为是贝叶斯方法的扛鼎之作,我有幸忙里偷闲地把这本书通读了一遍并且也把各个章节的习题几乎完成了一遍,可以见我的博客,作为看完这本书最后一个环节,我想为我看完这本书做一个总结。总结分为如下几个部分,分别是阅读此书可以采取的方法,本书主要内
2016-12-29 19:25:22 8247 2
原创 119:Search a 2D Matrix II
题目:Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted in ascending from left to right. Integers in ea
2017-03-26 11:46:30 305
原创 118:Search a 2D Matrix
题目:Write an efficient algorithm that searches for a value in an mn matrix. This matrix has the following properties: • Integers in each row are sorted from left to right. • The first integer of eac
2017-03-26 11:39:59 307
原创 117:Search for a Range
题目:Given a sorted array of integers, find the starting and ending position of a given target value. Your algorithm’s runtime complexity must be in the order of O(log n). If the target is not found in
2017-03-26 11:32:00 267
原创 116:Kth Largest Element in an Array
题目:Find the k -th largest element in an unsorted array. For example, given [3,2,1,5,6,4] and k = 2 , return 5. Note: You may assume k is always valid, 1 ≤ k ≤ array’s length.解析1:堆排序,维护一个 k 大小的小根堆,将数组中
2017-03-25 19:55:19 331
原创 115:Largest Number
题目:Given a list of non negative integers, arrange them such that they form the largest number. For example, given [3, 30, 34, 5, 9] , the largest formed number is 9534330 . Note: The result may be ve
2017-03-25 19:45:59 270
原创 114:Sqrt(x)
题目:Implement int sqrt(int x). Compute and return the square root of x.该题目比较简单,可以使用二分法,代码如下:// 二分查找// 时间复杂度 O(logn),空间复杂度 O(1)class Solution {public: int mySqrt(int x) { int l
2017-03-25 19:41:02 230
原创 113:Pow(x,n)
题目:Implement pow(x, n).解析1:使用递归法,因为xn=(x2)n/2∗xn%2 x^n = (x^2)^{n / 2} * x^{n\%2},代码如下:// 递归法,时间复杂度 O(logn)// 注意:-5 / 2 = -2, -5 % 2 = -1;class Solution {public: double myPow(double x, int n
2017-03-25 19:39:09 216
原创 112:Maximum Gap
题目:Given an unsorted array, find the maximum difference between the successive elements in its sorted form. Try to solve it in linear time/space. Return 0 if the array contains less than 2 elements.
2017-03-25 19:33:20 255
原创 111: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
2017-03-25 19:30:21 403
原创 110:Sort Colors
题目:Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue. Here, we will use the integers
2017-03-25 19:21:34 195
原创 109:First Missing Positive
题目:Given an unsorted integer array, find the first missing positive integer. For example, Given [1,2,0] return 3, and [3,4,-1,1] return 2. Your algorithm should run in O(n) time and uses constant spa
2017-03-25 19:16:25 200
原创 108:Sort List
题目:Sort a linked list in O(nlogn) time using constant space complexity。解析:可以使用归并排序算法,将链表从中间分开,然后将这中间分开的两段链表分别排序,再合并。时间复杂度为 O(nlogn)class Solution {public: ListNode* sortList(ListNode* head) {
2017-03-25 19:11:51 183
原创 107:Insertion Sort List
题目:Sort a linked list using insertion sort代码如下:// 时间复杂度 O(n^2),空间复杂度 O(1)class Solution {public: ListNode* insertionSortList(ListNode* head) { if (!head) return head;
2017-03-25 19:06:34 211
原创 106:Merge k Sorted Lists
题目:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.解析1:反复调用 merge two sorted lists 函数,假设每条链平均长度为 n,则时间复杂度为 O(2n + 3n + … + kn) = O(nk^2),代码如下:class Sol
2017-03-25 19:03:12 224
原创 105: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 to hold additional elements from B. The number of elements initialized in A
2017-03-25 18:54:50 203
原创 104:Factorial Trailing Zeroes
题目:Given an integer n , return the number of trailing zeroes in n! . Note: Your solution should be in logarithmic time complexity.解析:计算阶层尾0数目的公式为 N = n / 5 + n / 5^2 + n / 5^3 + …代码如下:/ 时间复杂度 O(log n)
2017-03-19 13:42:33 251
原创 103:Fraction to Recurring Decimal
题目:Given two integers representing the numerator and denominator of a fraction, return the fraction in string format. If the fractional part is repeating, enclose the repeating part in parentheses.
2017-03-19 13:40:24 259
原创 103:Fraction to Recurring Decimal
题目:Given two integers representing the numerator and denominator of a fraction, return the fraction in string format. If the fractional part is repeating, enclose the repeating part in parentheses.
2017-03-19 00:13:38 213
原创 102:Super Ugly Number
题目:Write a program to find the nth super ugly number.Super ugly numbers are positive numbers whose all prime factors are in the given prime list primes of size k. For example, [1, 2, 4, 7, 8, 13, 14, 1
2017-03-16 23:07:42 198
原创 101:Ugly Number II
题目:Write a program to find the n-th ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of the first 10 u
2017-03-16 23:05:19 204
原创 100:Ugly Number
题目:Write a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly since it
2017-03-16 23:00:24 161
原创 99:Happy Number
题目:Write an algorithm to determine if a number is “happy”.A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares o
2017-03-16 22:58:09 175
原创 98:Maximal Rectangle
题目:Given a 2D binary matrix filled with 0’s and 1’s, find the largest rectangle containing all ones and return its area. For example, given the following matrix: 1 0 1 0 0 1 0 1 1 1 1 1 1 1 1 1 0
2017-03-15 23:30:25 161
原创 97:Maximal Square
题目:Given a 2D binary matrix filled with 0’s and 1’s, find the largest square containing only 1’s and return its area.For example, given the following matrix:1 0 1 0 0 1 0 1 1 1 1 1 1 1 1 1 0 0 1 0
2017-03-15 23:14:33 184
原创 96:Palindrome Partitioning II
题目:Given a string s, partition s such that every substring of the partition is a palindrome. Return the minimum cuts needed for a palindrome partitioning of s. For example, given s = “aab”, Return 1
2017-03-14 23:35:15 216
原创 95:Palindrome Partitioning
题目:Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. For example, given s = “aab”, Return [ [“aa”,”b”], [“
2017-03-14 23:31:03 152
原创 94:Maximum Subarray
题目:Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example, given the array [−2,1,−3,4,−1,2,1,−5,4], the contiguous subarray [4,−1,2,1] has
2017-03-13 23:22:23 159
原创 93:Triangle
题目:Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below. For example, given the following triangle [ [2], [3,4], [6,5,7], [
2017-03-13 23:15:35 178
原创 92:Container With Most Water
题目:Given n non-negative integers a1; a2; :::; an, where each represents a point at coordinate (i; ai). n vertical lines are drawn such that the two endpoints of line i is at (i; ai) and (i; 0). Find t
2017-03-13 08:35:23 218
原创 91:Longest Substring Without Repeating Characters
题目:Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for “abcabcbb” is “abc”, which the length is 3. F
2017-03-12 23:15:18 207
原创 90:Best Time to Buy and Sell Stock II
题目:Say you have an array for which the i-th element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy
2017-03-12 23:10:05 204
原创 89:Best Time to Buy and Sell Stock
题目:Say you have an array for which the i-th element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock
2017-03-12 23:08:24 175
原创 88:Jump Game II
题目:Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position. Your goal is
2017-03-12 14:56:35 180
原创 87 :Jump Game
题目:Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position. Determine if yo
2017-03-12 14:54:38 175
原创 86:Sqrt(x)
题目:Implement int sqrt(int x). Compute and return the square root of x.解题代码如下:下面代码的思想及编写参考了网址https://github.com/soulmachine/leetcode#leetcode题解题目// 二分查找// 时间复杂度 O(logn),空间复杂度 O(1)class Solution {pub
2017-03-11 22:03:26 185
原创 85:Pow(x,n)
题目:Implement pow(x, n).该题有递归和迭代两种解法解析1:递归方法,代码如下:// 递归法,时间复杂度 O(logn)// 注意:-5 / 2 = -2, -5 % 2 = -1;class Solution {public: double myPow(double x, int n) { if (n < 0) return
2017-03-11 22:01:50 217
原创 84:Sum Root to Leaf Numbers
题目:Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number. An example is the root-to-leaf path 1->2->3 which represents the number 123. Find the total su
2017-03-10 23:52:15 223
原创 83:Populating Next Right Pointers in Each Node
题目:见https://leetcode.com/problems/populating-next-right-pointers-in-each-node/?tab=Description解析1:由于该题目要求使用常数空间,因此只能使用迭代法,代码如下,注意代码也能适用该问题的第二个版本https://leetcode.com/problems/populating-next-right-point
2017-03-10 23:15:59 145
原创 82:Binary Tree Maximum Path Sum
题目:Given a binary tree, find the maximum path sum. The path may start and end at any node in the tree. For example: Given the below binary tree, 1 / \ 2 3 Return 6.下面代码的思想及编写参考了网址https://github.co
2017-03-10 22:40:47 110
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人