自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(47)
  • 资源 (4)
  • 收藏
  • 关注

原创 剑指offer-47:不用加减乘除做加法

代码public int Add(int num1,int num2) { int sum = 0, carry = 0; // 1. 使用异或运算表示各个位加和后的结果; // 2. 根据计算结果发现,只有1,1进位,于是求与运算且左进一位; // 3. 更新num1, num2,直到num2为0 // 4. 返回num

2017-04-18 10:41:29 339

原创 剑指offer-57:删除链表中重复节点

思路需要新建一个头指针header, prev = header; nHead = pHead,以防链表第一个元素重复;遍历链表当前值与next指针的值,若相同则循环直至不同,令prev.next指向当前指针的下一个;反之若值不相同,prev.next指向该值,更新prev;判断结束后,nHead = nHead.next代码public ListNode deleteDuplicatio

2017-04-18 09:24:20 370

原创 剑指offer-20:顺时针打印矩阵

思路因为是自己想的笨办法,所以代码不优雅哈 1. 设置变量cur表示每次移动方向,初始化为1,每次与4取余表示方向; 2. 在每个方向遍历过程中注意横纵坐标边界与cur之间的变化; 3. 循环终止条件为集合res保存个数等于总个数。代码 public ArrayList<Integer> printMatrix(int [][] matrix) { int row = matri

2017-04-08 17:45:05 310

原创 剑指offer-25 二叉树中和为某一值的路径

思考判断路径肯定使用深度遍历;遍历到一个叶结点后需要返回上一父节点;因此在函数的最后应该将末尾元素删除;保存结果方式,不可能在函数中定义容器,因此可以将结果作为函数参数,在函数递归过程中依次更新数据。(类似mergeSort中将整理的数组传递给新建的空间数组,最后再遍历更新原来的数组)代码public static ArrayList<ArrayList<Integer>> FindPath

2017-04-03 10:47:53 300

原创 剑指offer-16:反转链表

非递归方法public ListNode ReverseList(ListNode head) { // q,当前指针; // p,当前指针的前一个节点 // cur,保存当前指针下一个节点,中间变量 ListNode p = null, q = head, cur = head; if(head == null || h

2017-04-01 15:29:36 354

原创 剑指offer-判断树是否对称

分析若根节点为空,返回TRUE;不为空,判断左右两颗子树是否对称,即左子树的左孩子==右子树的右孩子 && 左子树的右孩子==右子树的左孩子。递归判断函数中,注意递归出口。代码public class Solution { boolean isSymmetrical(TreeNode pRoot) { if(pRoot == null) return true

2017-04-01 14:39:12 379

原创 剑指offer-树的子结构

分析大体思路如下: 判断当前节点与查询节点的val是否相等,若相等,则去检查两者的左右子树;反之return false;在程序递归过程中,记得注意递归的出口以及空指针的处理;主程序中在root1&root2非空的条件下才能去判断;判断judge函数中,一些边界出口为if(root2 == null) return true;if(root1 == null) return false

2017-04-01 14:22:11 272

原创 找零钱问题

分析定义状态变量:int[] V表示拥有不同种类的零钱对应金额,S表示总金额;定义一个int[S+1]存储对应下标金额需要的零钱最少数,s[0] = 0, others为最大值-1;状态转移:将零钱金额数组从大到小开始遍历,若满足当前零钱金额小于总金额,且总金额减去当前金额所需纸币数+1(1表示使用当前零钱)< res[i]_cur; 更新。if(V[j] <= i && res[i] >

2017-03-30 10:52:22 414

原创 跳格子

问题描述平面上有N*M个格子,每次只能向右或者向上走一步,问从起点到右上角一共多少条路径?分析这道题,数学中的组合问题,结果为 cmm+nc_{m+n}^{m};注意: 1. 应该开辟int[m+1][n+1]的空间,否则给出的就是 cm−1m+n−2c_{m+n-2}^{m-1} 2. 记得初始化边界代码public static int LeapGrid(int m, int n){

2017-03-30 10:44:45 491

原创 机器学习优化方法小结

最优化理论知识小结一. 梯度下降法一阶最优化算法,梯度其实是有方向的。若找到一个函数的局部极小值,必须向函数上当前点对应梯度的反方向的规定步长距离点进行迭代搜索;若向梯度正方向搜索,会接近函数的局部极大值,称为梯度上升法。优点: 简单易行缺点: 靠近极小值时速度减慢。二. 牛顿法,拟牛顿法,L-BGFS牛顿法是使用函数f(x)的泰勒级数的前面几项来寻找f(x)=0f(x)=0的根。 基本思想是

2017-03-23 20:53:21 802

原创 线性代数Lec04:A的LU分解

目标:消元矩阵的乘法审视高斯消元1. 矩阵可逆的顺序假设矩阵A,BA,B可逆,那么(AB)−1(AB)^{-1}是什么? 根据AA−1=IAA^{-1}=I, 因此(AB)−1=B−1A−1(AB)^{-1}=B^{-1}A^{-1};AB(B−1A−1)=A(BB−1)A=IAB(B^{-1}A^{-1}) = A(BB^{-1})A=I2.消元矩阵给定二元矩阵E32A=UE_{32}A=U,

2016-09-17 09:56:43 2047

原创 线性代数Lec03:矩阵乘法和逆

一 矩阵乘法矩阵乘法可以有多种方法解释 假设矩阵Am∗n∗Bn∗p=Cm∗pA_{m*n}*B_{n*p}=C_{m*p}1. 传统rows(A)*cols(B)对于矩阵C34C_{34}求解方式如下: C34=A31B14+A32B24+....+A3nBn4C_{34}=A_{31}B_{14}+A_{32}B_{24}+....+A_{3n}B_{n4} 整理为: C34=∑k=1nA

2016-09-12 18:33:44 803

原创 线性代数Lec02: 矩阵消元

消元法1 Success2 Failure回代消元矩阵矩阵相乘1. 消元法⎡⎣⎢130284111⎤⎦⎥(1)\left[ \begin{matrix} 1 & 2 & 1\\ 3 & 8 & 1 \\ 0 & 4 & 1 \\ \end{matrix} \right] \tag{1} 依次消去主元1(x),主元2(y);(2)中对角线上的元素依次为主元 ⎡⎣⎢

2016-09-12 18:31:16 454

原创 线性代数Lec01

两种观点row picture: 通过绘图进行找解(三维以上很难解)column picture: 列向量的线性组合Ax = b, 对于任意的向量b,是否都有解。A为非奇异矩阵,可逆(即行列式不为0) 对于三维,若三个向量在同一个面上,线性相关,对于任意的其他向量,不一定有解。具体解释下面给出一个方程组: 2x−y=0−x+2y=3\begin{array}{r}2x - y =0 \

2016-09-12 18:29:19 382

原创 Leetcode-11. 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

2016-06-12 19:45:12 334

原创 Leetcode-44. Wildcard Matching

题目介绍Implement wildcard pattern matching with support for ‘?’ and ‘*’. ‘?’ Matches any single character. ‘*’ Matches any sequence of characters (including the empty sequence). The matching sho

2016-06-12 17:13:36 285

原创 Leetcode-70. 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 distinct ways can you climb to the top?解法思路: a. n==0, f(n) =

2016-06-06 23:34:09 303

原创 Leetcode-10. Regular Expression Matching

题目介绍 ‘.’ Matches any single character. ‘*’ Matches zero or more of the preceding element. The matching should cover the entire input string (not partial). The function prototype should b

2016-06-06 21:23:56 377

原创 Leetcode-69 Sqrt(x)

题目介绍 Implement int sqrt(int x). Compute and return the square root of x.解决方法int sqrt(int x) { if (0 == x) return 0; int left = 1, right = x, ans; while (left <= right) {

2016-06-05 17:33:00 437

原创 Leetcode-Power of 2,3,4

问题描述 Given an integer, write a function to determine if it is a power of x.(在这里,我们考虑x=2,3,4三种情况) Follow up: Could you do it without using any loop / recursion?一般解法 以x==3为例 bool isPowerOfT

2016-06-03 18:03:38 421

原创 Leetcode - 14. Longest Common Prefix

题目介绍 Write a function to find the longest common prefix string amongst an array of strings.思路以第一个字符串作为参照,与其他字符串比较对应位置的字符是否相等;在遍历首字符串的过程中,遍历比较vector。若都相等,将该字符添加在结果中,然后继续; 反之跳出循环;注意:若vector为空,则返回”“

2016-05-29 11:25:46 318

原创 Leetcode-13. Roman to Integer

问题介绍 Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. 方法思路: 1. 对每个字符进行数字的映射,这里存储在数组中; 2. 遍历字符串,针对IV,VI等这类数字,使用两个指针表示,若发现前者小于后者,结果su

2016-05-26 16:43:59 325

原创 Leetcode-12. Integer to Roman

问题介绍 Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999. 解决方法思路: 空间换时间 string intToRoman(int num) { string M[4] ={"","M","MM",

2016-05-26 16:33:38 296

原创 TED-如何系列

如何养成一个好习惯/改掉一个坏习惯?triggerbehaviorreward如何在公众演讲? a. Focus on one idea b. Give people a reason to care c. Build your idea with familiar concepts d. Make your idea worth sharing如何活得更加开心,更加长寿? 通过哈

2016-05-24 20:10:44 552

原创 Leetcode - 15. 3Sum

题目介绍 Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero. Note: Elements in a triplet (a

2016-05-23 00:39:50 366

原创 Leetcode - 20. Valid Parentheses

题目介绍 Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[’ and ‘]’, determine if the input string is valid. The brackets must close in the correct order, “()” and “()[]{}” are al

2016-05-22 20:19:47 331

原创 Leetcode-349 Intersection of Two Arrays

题目介绍 Given two arrays, write a function to compute their intersection. Example: Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2]. Note: Each element in the result must be unique

2016-05-22 20:11:12 421

原创 SpatialSpark和SparkDistributedMatrix调研小结

SpatialSpark和SparkDistributedMatrix调研小结最近接触了github上两个基于spark的项目,现在做一个小结,这两个项目的链接会在下面具体介绍中给出。SpatialSparkSpatialSpark是一个基于Spark用来处理空间数据的一个分布式数据处理系统。在系统中,它提供了丰富的空间查询操作,同时为了实现高性能运算,采用了多种不同的空间索引结构。下面简单的介绍下

2016-05-20 15:32:23 2372

原创 Leetcode - 19. Remove Nth Node from end of List

19. Remove Nth Node From End of List问题简介Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing

2016-05-10 16:36:02 368

原创 Leetcode - 88. Merge Sorted Array

题目简介 Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note: You may assume that nums1 has enough space (size that is greater or equal to m + n) to

2016-05-10 16:34:35 352

原创 Leetcode - 21. Merge Two Sorted Lists

问题简介 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.Tags : Linked List方法一class Solution {public: Li

2016-05-10 16:33:22 390

原创 Leetcode - 38. Count and Say

38. 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”

2016-05-06 22:14:18 1159

原创 Leetcode - 5. Longest Palindromic Substring

题目 Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.Simple solution(超时)思路

2016-05-06 20:40:54 406

原创 Leetcode - 4. Median of Two Sorted Arrays

4. Median of Two Sorted Arrays题目简介 There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log

2016-05-06 19:42:20 543

原创 Install Ruby on rails on Ubuntu 14.04 LST

Install Ruby on rails on Ubuntu 14.04 LST安装rails历经两天,看了网上许多教程,最后以该博客为准尝试安装终于成功。安装过程中有某些地方不一致,但大体相同。在本文最后部分将会介绍安装过程中遇到的一些问题与解决办法。快捷键加粗 Ctrl + B 斜体 Ctrl + I 引用 Ctrl + Q插入链接 Ctrl + L插入代码

2015-09-25 11:30:59 561

原创 新建Dynamic web project 没有web.xml

原因:创建Dynamic web module version这个选项默认成了3.0,按照老规范,应该是在eclipse的WebContent \ WEB-INF \ 目录下创建web.xml的而新规范是可以不用web.xml的,如tomcat 7.0就支持新规范,这样相关的servlet配置会以注解的形式直接写到代码里面了,比如@WebServlet。解决方法

2013-12-12 11:34:00 719

转载 思想决定高度,行动决定宽度

注:这是一篇转载的文档,写的很好,每次读完后都会感到一种积极的力量。     有人工作,有人上学,大家千万不要错过这篇文章,相信多年以后,再来看这篇文章,一定有不同的感觉。 正如"打工皇帝"唐骏说:"我觉得有两种人不要跟别人争利益和价值回报。第一种人就是刚刚进入企业的人,头5年千万不要说你能不能多给我一点儿工资,最重要的是能在企业里学到什么,对发展是不是有利……"    人总是从平

2013-08-16 20:33:29 1980

原创 MIT算法导论5——线性时间排序

常见的排序算法,像归并排序,堆排序时间复杂度为O(nlgn);像冒泡排序,插入排序则为O(n^2)。对于排序算法而言,只要你是通过比较,O(nlgn)是一条难以逾越的界限。为了追求更快的速度,智慧的人类发明了一种新的方法——计算排序(Counting sorts),在这种算法中没有比较运算,下面简单的介绍一下。        对于这个算法,有个比较重要的约束条件——排列的数据必须在特定的范围,

2013-08-11 11:23:26 753

转载 真实的哈佛

哈佛校园里,不见华服,不见LV包,不见化妆,不见着名牌的教授学生,不见豪车接美女,更不见晃里晃荡,只有匆匆的脚步,坚实地写下人生的篇章。哈佛不是神话,哈佛只是一个证明,人的意志,精神,抱负,理想的证明。日前,两张美国哈佛大学图书馆凌晨4点多学生仍在学习的照片,在网上迅速传播:凌晨4点的哈佛大学图书馆里,灯火通明,座无虚席……图片配文这样写道:哈佛是一种象征。人到底有怎样的发挥潜力?人的意志

2013-08-11 10:47:07 754

转载 脸部各部位长痘痘的原因

1. 额头长痘: 原因:压力大,心火旺,脾气差,常生气,造成心火和血液循环有问题。 改善:早睡早起,多喝水。 2.太阳穴: 太阳穴附近出现小粉刺,显示你的饮食中包含了过多的加工食品,造成胆囊阻塞,需要赶紧行体内大扫除 ;在经络中是属于汇集与舒解的位置,当消化系统不良时就会长痘。 3. 双眉间长痘: 原因:胸闷,心律不整,心悸。 改善:不要做太过激烈的运动,避免烟

2013-08-11 10:45:20 1629

大学各种论文格式标准及word讲解

这是我准备大学里用到的论文标准格式,并且还附有相应论文使用word的排版使用方法,希望给大家提供帮助。

2013-06-09

ACM程序设计中常用的解题策略

ACM程序设计中常用的解题策略,这是计算机程序设计竞赛权威指导书,北京大学出的,里面包含丰富的试题。

2013-03-27

电话簿的简易编程

名字是C++——电话簿管理程序;PPT中介绍了有关编程的过程和代码,适合初学者的,挺有帮助的。

2012-05-05

C语言经典实例

这是学习C语言中,经典例题,挺经典的;希望能帮助你更好地学习。

2012-03-27

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除