- 博客(52)
- 收藏
- 关注
原创 LeetCode 之 Search in Rotated Sorted Array II
Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Write a function to determine if a given target is in the
2016-05-09 22:40:40
349
原创 LeetCode 之 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
2016-05-09 13:22:58
294
原创 LeetCode 之 Search in Rotated Sorted Array
Suppose a sorted array 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 are given a target value to search. If found in the array retur
2016-05-06 15:59:03
310
原创 LeetCode 之 Find Minimum in Rotated Sorted Array II
Follow up for "Find Minimum in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Suppose a sorted array is rotated at some pivot unk
2016-05-06 14:49:11
322
原创 LeetCode 之 Perfect Squares
Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n.For example, given n = 12, return 3 because 12 = 4 + 4 + 4; given n =
2016-05-06 14:03:10
251
原创 LeetCode 之 Remove Duplicates from Sorted Array
Follow up for "Remove Duplicates":What if duplicates are allowed at most twice?For example,Given sorted array nums = [1,1,1,2,2,3],Your function should return length = 5, with the first fi
2016-05-03 21:47:34
275
原创 LeetCode 之 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 tota
2016-05-02 22:24:31
274
原创 LeetCode 之 Increasing Triplet Subsequence
Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the array.Formally the function should:Return true if there exists i, j, k such that arr[i] ar
2016-04-12 11:23:09
248
原创 LeetCode 之 Set Matrix Zeroes
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.第一种方法:遍历一遍矩阵,用两个数组分别标示行和列是否存在0元素,第二次遍历按照这两个标示数组把矩阵置零,代码如下:void setZeroes(vector>& matrix) { i
2016-04-12 10:18:57
314
原创 数据挖掘/机器学习 之 面试总结
从过年到现在我找实习,先后面了:新浪微博,360,支付宝,百度地图,岗位都是关于数据挖掘和机器学习的,现在把面试经验总结如下:简历的问题,要为每一个岗位做特定的简历,简历上和这个岗位无关的东西最好不要写或者少些,比如我去新浪微博面试,面试官上来就说我是搞通信的不懂机器学习啥的。。。当时还没有经验简历上无关的东西确实多。由于机器学习中的模型算法特别的多,面试时面试官也不会全问,一般都会让
2016-04-11 22:09:28
2761
原创 数据挖掘/机器学习 之 距离测度
某空间下的距离测度是一个函数d(x,y),该函数满足下列准则:d(x,y)>=0 (距离非负)d(x,y)=0,当且仅当x=yd(x,y)=d(y,x)(对称性)d(x,y)常见的有:欧氏距离Jaccard距离余弦距离编辑距离:两个字符串x,y把x替换为y所需要的单支付插入及删除操作的最小数目,一种计算的方法是:找到最长公共子序列(LCS),编辑距离等于x与y的长度
2016-04-11 21:15:17
2490
原创 数据挖掘/机器学习 之 聚类
聚类:对点集进行考察并按照某种距离测度将他们聚成多个簇的过程,目标是使得同一个簇内的点之间距离比较短,不同簇中点的距离较大一般是从给定的数据中发现簇,尤其是大数据量及高维空间或非欧空间点集是一种适合于聚类的数据集,每个点都是某空间下的对象,能够进行聚类的所有空间都有一个距离测度,即空间下任意两点的距离聚类策略:层次(hierarchical或者凝聚式agglomerativ
2016-04-11 17:17:01
800
原创 LeetCode 之 Summary Ranges
Given a sorted integer array without duplicates, return the summary of its ranges.For example, given [0,1,2,4,5,7], return ["0->2","4->5","7"].由于数组是已经排好序的,所以只需要两个指针,一个指向连续序列的开头,一个指向连续序列的结束,遇到间
2016-04-11 13:38:51
253
原创 LeetCode 之 Search a 2D Matrix
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 from left to right.The first integer of each
2016-04-11 13:01:25
247
原创 LeetCode 之 Combinations
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.For example,If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4],]
2016-04-11 12:12:32
296
原创 数据挖掘/机器学习 之 开新坑
之前的博客一直是关于LeetCode的内容,接下来除了这个外我还会写关于数据挖掘/机器学习的一些东西,开一个新的坑。这个一个方向将会是我的重心,近期的计划包括:面试经验书籍阅读笔记自己的一些感想和经验在这里我先介绍下我的心路历程:我本科和研究生的方向和数据挖掘/机器学习其实不太沾边,甚至和计算机都太沾边。自己之所以私下里搞这个方向主要是自己真的很喜欢,本科时喜欢玩每天过的比较潇
2016-04-10 23:08:59
465
原创 LeetCode 之 Binary Tree Right Side View
Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.For example:Given the following binary tree, 1
2016-04-10 22:23:39
412
原创 LeetCode 之 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
2016-03-18 23:01:26
329
原创 LeetCode 之 Find Minimum in Rotated Sorted Array
Suppose a sorted array 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).Find the minimum element.You may assume no duplicate exists in
2016-03-18 22:59:01
368
原创 LeetCode 之 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
2016-03-17 11:00:19
238
原创 LeetCode 之 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). Fin
2016-03-17 10:02:41
230
原创 LeetCode 之 Combination Sum III
Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.Ensure that numbers wi
2016-03-14 22:12:54
283
原创 LeetCode 之 Permutations
Given a collection of distinct numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1].这道全排
2016-03-14 21:09:59
238
原创 LeetCode 之 Unique Paths
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the
2016-03-13 19:37:43
310
原创 LeetCode 之 Binary Tree Preorder Traversal
Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,2,3].Note: Recursive soluti
2016-01-22 14:45:59
386
原创 LeetCode 之 Missing Number
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.For example,Given nums = [0, 1, 3] return 2.Note:Your algorithm sho
2016-01-21 11:55:15
221
原创 LeetCode 之 Bulb Switcher
There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every third bulb (turning on if it's off or turning off
2016-01-19 21:39:15
265
原创 LeetCode 之 Product of Array Except Self
Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Solve it without division and in O
2016-01-14 22:47:37
242
原创 LeetCode 之 Best Time to Buy and Sell Stock II
Say you have an array for which the ith 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 on
2016-01-14 22:01:12
278
原创 LeetCode 之 Compare Version Numbers
Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 version2 return -1, otherwise return 0.You may assume that the version strings are non-empty and co
2015-12-20 18:34:11
379
原创 LeetCode 之 Implement strStr()
Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.首先要搞懂strStr()是啥,strStr()是判断一个字符串是否为另一个字符串的子串。最简单的算法是遍历(m-n)*n次,代码如下:
2015-12-07 19:50:52
296
原创 LeetCode 之 Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321从低到高位,对每个数字乘以翻转后的权值,在求和就行了,代码如下:class Solution {public: int reverse(int x) { long ans
2015-12-06 21:21:11
260
原创 LeetCode 之 Binary Tree Paths
Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:["1->2->5", "1->3"]又是较
2015-12-06 15:55:21
407
原创 LeetCode 之 Palindrome Linked List
Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?方法一:反序存一个新的链,在遍历两个链,进行比较,代码如下: bool isPalindrome(ListNode* head) {
2015-12-05 22:06:19
245
原创 LeetCode 之 Bulls and Cows
You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide a hint t
2015-12-05 20:35:31
240
原创 LeetCode 之 Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".这道题并不复杂,需要注意的是要从后往前遍历a,b求和,同时要有一个进位项,对各种情况都要分析到:string addBinary(string a, str
2015-12-04 20:51:55
228
原创 LeetCode 之 Count and Say
The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11.11 is read off as "two 1s" or 21.21 is read off as
2015-12-04 10:41:45
234
原创 LeetCode 之 Remove Linked List Elements
Remove all elements from a linked list of integers that have value val.ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2 --> 3 --> 4 --> 5简单的链表操作:/** * Definit
2015-12-03 22:52:45
298
原创 LeetCode 之 Isomorphic Strings
Given two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to get t.All occurrences of a character must be replaced with anot
2015-12-02 19:14:54
252
原创 LeetCode 之 Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.BST中深度的问题,我们可以递归(DFS),也可以迭代解决(BFS)
2015-11-30 22:20:58
221
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人