03 2015 档案
摘要:Given a linked list, swap every two adjacent nodes and return its head.For example,Given1->2->3->4, you should return the list as2->1->4->3.Your algor...
阅读全文
摘要:Given an array withnobjects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, wh...
阅读全文
摘要:A robot is located at the top-left corner of amxngrid (marked 'Start' in the diagram below).The robot can only move either down or right at any point ...
阅读全文
摘要:Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e.,0 1 2 4 5 6 7might become4 5 6 7 0 1 2).Find the minimum element.You m...
阅读全文
摘要:Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.一直没想出原址排序...
阅读全文
摘要:Given an array where elements are sorted in ascending order, convert it to a height balanced BST.分治是比较好而且容易想到的思路。 1 class Solution { 2 public: 3 T...
阅读全文
摘要:A robot is located at the top-left corner of amxngrid (marked 'Start' in the diagram below).The robot can only move either down or right at any point ...
阅读全文
摘要:You are climbing a stair case. It takesnsteps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb...
阅读全文
摘要:Given a sorted linked list, delete all duplicates such that each element appear onlyonce.简单题,注意逻辑顺序就好了。 1 class Solution { 2 public: 3 ListNode *d...
阅读全文
摘要:Given an array of sizen, find the majority element. The majority element is the element that appears more than⌊ n/2 ⌋times.You may assume that the arr...
阅读全文
摘要: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,...
阅读全文
摘要: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 a binary tree, return theinordertraversal of its nodes' values.和preorder是一样的,把左子节点一直压入到栈中,直到没有左子节点为止,然后出栈访问,存储右子节点。 1 vector inorderTraversal(Tr...
阅读全文
摘要:Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set toNULL.Initially, all next ...
阅读全文
摘要:Given a binary tree, return thepreordertraversal of its nodes' values.简单题,递归和迭代都可以解。 1 class Solution { 2 public: 3 vector preorderTraversal(TreeN...
阅读全文
摘要:最近一直在回顾linear regression model和logistic regression model,但对其中的一些问题都很疑惑不解,知道我看到广义线性模型即Generalized Linear Model后才恍然大悟原来这些模型是这样推导的,在这里与诸位分享一下,具体更多细节可以参...
阅读全文
摘要:Given a linked list, determine if it has a cycle in it.简单题,只要知道快慢指针这个技巧就很容易解了。 1 class Solution { 2 public: 3 bool hasCycle(ListNode *head) { 4 ...
阅读全文
摘要:Given a column title as appear in an Excel sheet, return its corresponding column number.本质上是一个进制转换问题。1 class Solution {2 public:3 int titleToNumb...
阅读全文
摘要:Givenn, how many structurally uniqueBST's(binary search trees) that store values 1...n?简单动态规划。判别每个左右子树各有多少种情况,然后相乘就可以了,而且是BST,注意这条件就可以解了。它的状态转移方程为: ...
阅读全文
摘要:Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical an...
阅读全文
摘要:Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest le...
阅读全文
摘要:Given an array of integers, every element appearstwiceexcept for one. Find that single one.非常简单的一道题。直接相异或剩下的那个数就是答案。原理是两个相等的数异或的值为0。1 class Solution {...
阅读全文
摘要:决策树是简单的,易懂的,易实现的,同样也是强大的。 决策树本身是一连串的if-else的组合,其最关键的问题就是对于一个输入数据集我们应该怎么去寻找这个if-else规则。按照先贤们的分法主要有如下几种:ID3,C4.5,CART。本文也将介绍这三种决策树。 一、ID3 要想弄明白ID3决...
阅读全文
摘要:Bagging 和 Boosting 都是一种将几个弱分类器(可以理解为分类或者回归能力不好的分类器)按照一定规则组合在一起从而变成一个强分类器。但二者的组合方式有所区别。 一、Bagging Bagging的思想很简单,我选取一堆弱分类器用于分类,然后最终结果投票决定,哪个票数多就属于哪一...
阅读全文
摘要:SVM是机器学习中神一般的存在,虽然自深度学习以来有被拉下神坛的趋势,但不得不说SVM在这个领域有着举足轻重的地位。本文从Hard SVM 到 Dual Hard SVM再引进Kernel Trick,然后推广到常用的Soft Kernel SVM。 一、Hard SVM SVM本身是从感知...
阅读全文
摘要:排序算法有很多种,本文主要介绍基本的排序算法和实现,并分析复杂度和稳定性。一、Ο(n2)的算法 1、插入排序 插入排序十分好理解,在无序的数组中选择一个数值,插入到有序的数组当中,这个过程是稳定的。实现代码如下: 1 template 2 void InsertionSort(vector &...
阅读全文