摘要: https://leetcode.com/problems/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 nu... 阅读全文
posted @ 2015-04-20 17:57 Acjx 阅读(313) 评论(0) 推荐(0) 编辑
摘要: 1. using 关键字 使用 using 关键字,可以将父类中被隐藏的函数暴露在子类中,但是需要注意的是,在相同情况下,子类函数的优先级更高。 2. 继承构造函数(C++11) 在c++11之前,构造函数、析构函数、赋值操作符,这些都不能被继承。但是,C++11允许我们使用 using 关键字来继承基类的构造函数。 示例1 示例2 3. 重写方法时的特殊情况 1)... 阅读全文
posted @ 2015-04-08 20:29 Acjx 阅读(712) 评论(0) 推荐(0) 编辑
摘要: 修改重写方法的特征 在大多数情况下,我们重写(override)一个 virtual 方法是为了改变它的实现。然后,有时我们却想改变该 virtual 方法的其他的特征,这往往会带来一系列问题。 1)改变方法的返回值类型 通常,子类在重写方法时,要保持与父类一致的函数原型,方法的实现可以改变,但是原型需要保持不变。 然而,事实却并非如此。在C++中,如果父类的 virtual 方法的返回值... 阅读全文
posted @ 2015-04-06 18:23 Acjx 阅读(311) 评论(0) 推荐(0) 编辑
摘要: 多重继承常常被认为是 OOP 中一种复杂且不必要的部分。多重继承面临 crash 的场景并非难以想象,来看下面的例子。 1. 名称冲突 来看以下情况: 如果 Dog 类以及 Bird 类都有一个名为 eat() 的方法,而子类又没有 override 该方法。如果此时调用子类的 eat() 方法,编译器就会报错,指出 eat() 的调用有歧义(不知道是调用从 Dog 类继承而来的 eat... 阅读全文
posted @ 2015-04-06 15:35 Acjx 阅读(2055) 评论(1) 推荐(1) 编辑
摘要: https://oj.leetcode.com/problems/copy-list-with-random-pointer/ A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null. Ret... 阅读全文
posted @ 2015-03-05 15:41 Acjx 阅读(357) 评论(0) 推荐(0) 编辑
摘要: https://oj.leetcode.com/problems/merge-k-sorted-lists/ Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. Solution: 1. O(nk2) runtime, O(1) space – Bru... 阅读全文
posted @ 2015-03-04 21:51 Acjx 阅读(926) 评论(0) 推荐(0) 编辑
摘要: https://oj.leetcode.com/problems/swap-nodes-in-pairs/ Given a linked list, swap every two adjacent nodes and return its head. For example,Given 1->2->3->4, you should return the list as 2->1->4->3.... 阅读全文
posted @ 2015-03-04 18:02 Acjx 阅读(385) 评论(0) 推荐(0) 编辑
摘要: https://oj.leetcode.com/problems/add-two-numbers/ You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single... 阅读全文
posted @ 2015-03-03 22:26 Acjx 阅读(332) 评论(0) 推荐(0) 编辑
摘要: 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. 水题,注意 dummy node 的使用即可,在不确定头节点的情况下,应该使用 dummy node,如此可以简化... 阅读全文
posted @ 2015-03-03 16:42 Acjx 阅读(300) 评论(0) 推荐(0) 编辑
摘要: Climbing Stairs https://oj.leetcode.com/problems/climbing-stairs/ You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many disti... 阅读全文
posted @ 2015-01-11 22:32 Acjx 阅读(353) 评论(0) 推荐(0) 编辑
摘要: Unique Paths https://oj.leetcode.com/problems/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 ... 阅读全文
posted @ 2015-01-11 20:11 Acjx 阅读(448) 评论(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]. ... 阅读全文
posted @ 2015-01-09 21:03 Acjx 阅读(292) 评论(0) 推荐(0) 编辑
摘要: 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. 题目意思很简单,就是给定一棵二叉... 阅读全文
posted @ 2015-01-06 15:41 Acjx 阅读(504) 评论(0) 推荐(0) 编辑
摘要: Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. Each number in C may only be used once in the combination... 阅读全文
posted @ 2014-12-28 20:08 Acjx 阅读(351) 评论(0) 推荐(0) 编辑
摘要: Given a digit string, return all possible letter combinations that the number could represent. A mapping of digit to letters (just like on the telephone buttons) is given below. Input:Digit string "2... 阅读全文
posted @ 2014-12-28 15:07 Acjx 阅读(388) 评论(0) 推荐(0) 编辑
摘要: Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. The same repeated number may be chosen from C unlimited number o... 阅读全文
posted @ 2014-12-28 12:30 Acjx 阅读(418) 评论(0) 推荐(0) 编辑
摘要: Given a collection of numbers that might contain duplicates, return all possible unique permutations. For example, [1,1,2] have the following unique permutations: [1,1,2], [1,2,1], and [2,1,1]. 以下是我... 阅读全文
posted @ 2014-12-24 21:27 Acjx 阅读(501) 评论(0) 推荐(0) 编辑
摘要: 1 定义 二叉树是树的一种特殊结构,在二叉树中每个结点最多只能有两个子结点。 二叉树结点的定义如下: struct BinaryTreeNode { int m_nValue; BinaryTreeNode *m_pLeft; BinaryTreeNode *m_pRight; }; 注意:在二叉树的前序遍历序列中,第一个数字总是... 阅读全文
posted @ 2014-11-18 15:39 Acjx 阅读(1452) 评论(0) 推荐(0) 编辑
摘要: 3. Model Representation I 1 神经网络是在模仿大脑中的神经元或者神经网络时发明的。因此,要解释如何表示模型假设,我们不妨先来看单个神经元在大脑中是什么样的。 我们的大脑中充满了如上图所示的这样的神经元,神经元是大脑中的细胞。其中有两点值得我们注意,一是神经元有像这样的细胞主体(Nucleus),二是神经元有一定数量的输入神经和输出神经。这些输入神经叫做树突(Dendri... 阅读全文
posted @ 2014-11-11 12:29 Acjx 阅读(6206) 评论(3) 推荐(1) 编辑
摘要: 在这篇文章中,我们一起来讨论一种叫作“神经网络”(Neural Network)的机器学习算法,这也是我硕士阶段的研究方向。我们将首先讨论神经网络的表层结构,在之后再具体讨论神经网络学习算法。 神经网络实际上是一个相对古老的算法,并且沉寂了一段时间,不过到了现在它又成为许多机器学习问题的首选技术。 1. Non-linear Hypotheses 之前我们已经介绍过线性回归和逻辑回归算法了,那为什... 阅读全文
posted @ 2014-11-10 11:38 Acjx 阅读(9190) 评论(3) 推荐(2) 编辑