03 2014 档案

摘要:关于线性回归,推荐几篇博文,讲得很好:JerryLead的对线性回归,logistic回归和一般回归的认识leftnoteasy的机器学习中的数学(1)-回归(regression)、梯度下降(gradient descent)苏冉旭的博客的Logistic regression (逻辑回归) 概述本文主要是我对线性回归的一些理解。一.线性回归 线性回归假设特征x和结果y满足线性关系。线性回归的目标函数为: 线性回归的损失函数为: 可以用梯度下降法或者最小二乘法调整θ来最小化这个J(θ)。 梯度下降法:J(θ)对θ求导得到: 那么θ的更新可以表示为: 最小二乘法:用no... 阅读全文
posted @ 2014-03-25 16:29 七年之后 阅读(834) 评论(0) 推荐(0)
摘要:K-近邻和最近邻(K=1)是模式识别中常用的分类方法,K-近邻算法思想是找到与当前样本相邻的K个有标签样本,然后通过投票决定此样本的类别。例如下图中如何分类未知的绿色圆圈呢? 例如我们可以取K=3个临近的样本时,通过投票(红色两个大于蓝色一个),从而将绿色圆圈归于红色三角一类。一.基于实例的学习 K-近邻和局部加权回归就是基于实例的学习。基于实例的学习过程只是简单的存储已知的训练数据,当遇到新的待分类样本时,将从训练数据中挑选出一系列相似的样本,并用来分类新的样本。 与常见的分类算法(如神经网络)不同的是,基于实例的方法可以为不同的待分类样本建立不同的函数逼近。只建立目标函数... 阅读全文
posted @ 2014-03-21 11:41 七年之后 阅读(1817) 评论(0) 推荐(0)
摘要:一.inode 在Linux中,“一切皆文件”。唯一标识文件的是inode而非文件名,文件名仅是为了方便人们的记忆和使用,系统或程序通过 inode 寻找正确的文件数据块。 什么是数据块呢?文件储存在硬盘上,硬盘的最小存储单位叫做"扇区"(Sector)。每个扇区储存512字节(相当于0.5K... 阅读全文
posted @ 2014-03-13 21:48 七年之后 阅读(1736) 评论(0) 推荐(0)
摘要:Given two words (startandend), and a dictionary, find all shortest transformation sequence(s) fromstarttoend, such that:Only one letter can be changed at a timeEach intermediate word must exist in the dictionaryFor example,Given:start="hit"end="cog"dict=["hot","dot 阅读全文
posted @ 2014-03-13 13:35 七年之后 阅读(236) 评论(0) 推荐(0)
摘要:Given two words (startandend), and a dictionary, find the length of shortest transformation sequence fromstarttoend, such that:Only one letter can be changed at a timeEach intermediate word must exist in the dictionaryFor example,Given:start="hit"end="cog"dict=["hot",&q 阅读全文
posted @ 2014-03-13 13:33 七年之后 阅读(229) 评论(0) 推荐(0)
摘要:Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given[100, 4, 200, 1, 3, 2],The longest consecutive elements sequence is[1, 2, 3, 4]. Return its length:4.Your algorithm should run in O(n) complexity.思考:空间换时间,查找O(1)用unordered_set。class Sol 阅读全文
posted @ 2014-03-13 09:56 七年之后 阅读(206) 评论(0) 推荐(0)
摘要:Given a strings, partitionssuch that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning ofs.For example, givens="aab",Return1since the palindrome partitioning["aa","b"]could be produced using 1 cut.class Solutio 阅读全文
posted @ 2014-03-12 22:10 七年之后 阅读(155) 评论(0) 推荐(0)
摘要:Given a strings, partitionssuch that every substring of the partition is a palindrome.Return all possible palindrome partitioning ofs.For example, givens="aab",Return [ ["aa","b"], ["a","a","b"] ]class Solution {private: vector > res;pub 阅读全文
posted @ 2014-03-12 21:27 七年之后 阅读(132) 评论(0) 推荐(0)
摘要:Given a stringsand a dictionary of wordsdict, add spaces insto construct a sentence where each word is a valid dictionary word.Return all such possible sentences.For example, givens="catsanddog",dict=["cat", "cats", "and", "sand", "dog"].A 阅读全文
posted @ 2014-03-12 20:36 七年之后 阅读(167) 评论(0) 推荐(0)
摘要:Givenn, generate all structurally uniqueBST's(binary search trees) that store values 1...n.For example,Givenn= 3, your program should return all 5 unique BST's shown below. 1 3 3 2 1 \ / / / \ \ 3 2 1 1 3 2 / / \ ... 阅读全文
posted @ 2014-03-12 20:26 七年之后 阅读(163) 评论(0) 推荐(0)
摘要:Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given"25525511135",return["255.255.11.135", "255.255.111.35"]. (Order does not matter)class Solution {private: vector ret; int pos[4];public: bool check 阅读全文
posted @ 2014-03-12 12:24 七年之后 阅读(181) 评论(0) 推荐(0)
摘要:Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like: 1 \ 2 \ 3 \ 4 \ 5 \ 6click to show hints.Hints:If y... 阅读全文
posted @ 2014-03-12 11:25 七年之后 阅读(230) 评论(0) 推荐(0)
摘要:Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; *//** * Definition for binary tree * struc... 阅读全文
posted @ 2014-03-12 10:22 七年之后 阅读(179) 评论(0) 推荐(0)
摘要:Given an array where elements are sorted in ascending order, convert it to a height balanced BST./** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: ... 阅读全文
posted @ 2014-03-11 22:41 七年之后 阅读(132) 评论(0) 推荐(0)
摘要:Given a binary tree, return thebottom-up level ordertraversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree{3,9,20,#,#,15,7}, 3 / \ 9 20 / \ 15 7return its bottom-up level order traversal as:[ [15,7] [9,20], [3],]conf... 阅读全文
posted @ 2014-03-11 21:38 七年之后 阅读(131) 评论(0) 推荐(0)
摘要:Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.Have you been asked this question in an interview?Yes/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right... 阅读全文
posted @ 2014-03-11 21:04 七年之后 阅读(144) 评论(0) 推荐(0)
摘要:Given a stringSand a stringT, count the number of distinct subsequences ofTinS.A subsequence of a string is a new string which is formed from the orig... 阅读全文
posted @ 2014-03-11 19:39 七年之后 阅读(160) 评论(0) 推荐(0)
摘要:Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.Have you been asked this question in an interview?Yes/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right;... 阅读全文
posted @ 2014-03-11 19:30 七年之后 阅读(150) 评论(0) 推荐(0)
摘要:A message containing letters fromA-Zis being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total number of ways to decode it.For example,Given encoded message"12", it cou 阅读全文
posted @ 2014-03-11 16:12 七年之后 阅读(111) 评论(0) 推荐(0)
摘要:The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integernrepresenting the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0.For example, givenn= 2, return[0,1,3,2]. Its gray code s 阅读全文
posted @ 2014-03-11 13:12 七年之后 阅读(122) 评论(0) 推荐(0)
摘要:Given a strings1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation ofs1="great": great / \ gr eat / \ / \g r e at / \ a tTo scramble the string, we may choose any non-leaf no... 阅读全文
posted @ 2014-03-11 11:35 七年之后 阅读(169) 评论(0) 推荐(0)
摘要:Givenn, how many structurally uniqueBST's(binary search trees) that store values 1...n?For example,Givenn= 3, there are a total of 5 unique BST's.1 3 3 2 1 \ / / / \ \ 3 2 1 1 3 2 / / \ \ 2 1 ... 阅读全文
posted @ 2014-03-10 17:07 七年之后 阅读(162) 评论(0) 推荐(0)
摘要:Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete at mosttwotransactions.Note:You may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again).Have you be 阅读全文
posted @ 2014-03-10 12:18 七年之后 阅读(175) 评论(0) 推荐(0)
摘要:Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one and sell one share of the stock multiple times). However, you may not engage in multiple transactions at 阅读全文
posted @ 2014-03-09 21:43 七年之后 阅读(171) 评论(0) 推荐(0)
摘要:Say you have an array for which theithelement is the price of a given stock on dayi.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), design an algorithm to find the maximum profit.Have you been asked this question in an interview?Yesclass 阅读全文
posted @ 2014-03-09 21:17 七年之后 阅读(129) 评论(0) 推荐(0)
摘要:Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".click to show clarification.Have you been asked this question in an interview?Yes思考:一开始没有考虑空格。去掉不合法空格+两次翻转,不需要额外空间。class Solution {public: void reverseWords(str 阅读全文
posted @ 2014-03-09 20:56 七年之后 阅读(326) 评论(0) 推荐(0)
摘要:Given a 2D board containing'X'and'O', capture all regions surrounded by'X'.A region is captured by flipping all'O's into'X's in that surrounded region.For example,X X X XX O O XX X O XX O X XAfter running your function, the board should be:X X X XX X X XX X X 阅读全文
posted @ 2014-03-09 13:41 七年之后 阅读(268) 评论(0) 推荐(0)
摘要:“完成一段代码,代码有三个线程。主线程有main进入,启动一个生产者和一个消费者线程。生产者线程随机产生整数,并且把这个整数放入一个List中,消费者从List中取出数据进行显示。”(摘自淘宝校招笔试题) 生产者-消费者问题是一个经典的线程同步问题。生产者将产品投入缓冲区,消费者从缓存区取... 阅读全文
posted @ 2014-03-06 19:26 七年之后 阅读(380) 评论(0) 推荐(0)
摘要:一.概念题1.线程的基本概念、线程的基本状态及状态之间的关系? 线程是进程中某个单一顺序的控制流,是程序执行流的最小单位。线程由线程ID、当前指令指针、寄存器集合和堆栈组成。线程是进程的一个实体,是被系统调度和分配的基本单位,线程与同一进程中的其他线程共享进程的全部资源。 线程有五种基本状态... 阅读全文
posted @ 2014-03-06 11:04 七年之后 阅读(1602) 评论(0) 推荐(0)
摘要:前言:有这样一道面试题(来自http://blog.csdn.net/morewindows/article/details/7392749): “编写一个程序,开启3个线程,这3个线程的ID分别为A、B、C,每个线程将自己的ID在屏幕上打印10遍,要求输出结果必须按ABC的顺序显示;如:ABC... 阅读全文
posted @ 2014-03-04 22:24 七年之后 阅读(6138) 评论(0) 推荐(0)