自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(25)
  • 收藏
  • 关注

原创 LeetCode 24. 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.Your algorithm should use only constant space. Y

2016-03-31 17:35:39 237

原创 蘑菇街笔试题1

题目一  搬圆桌现在有一张半径为r的圆桌,其中心位于(x,y),现在他想把圆桌的中心移到(x1,y1)。每次移动一步,都必须在圆桌边缘固定一个点然后将圆桌绕这个点旋转。问最少需要移动几步。输入描述:一行五个整数r,x,y,x1,y1(1≤r≤100000,-100000≤x,y,x1,y1≤100000)输出描述:输出一个整数,表示答案输入例子:

2016-03-31 16:33:23 590

原创 蘑菇街笔试题5

题目描述:给定一个字符串,问是否能够通过添加一个字母,使其变为回文。输入描述:一行由小写字母构成的字符串,字符串长度小于等于10输出描述:YES/NO例子:coco输出:YES分析:从微信公众号上看到的别人用Java的解题思路,即如果添加一个字符能变为回文串,那么删除对应位置上的字符,该字符串仍为回文。用一个循环,每次删掉一个字符,然后判断是否为回文

2016-03-31 16:17:44 471

原创 LeetCode 22. Generate Parentheses

Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:"((()))", "(()())", "(())()", "()(())", "()()

2016-03-30 20:19:57 229

原创 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.题目大意是将两个有序的链表合并成一个链表。 这道题比较简单,直接上代码了。/** * Definitio

2016-03-30 19:50:25 231

原创 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 all va

2016-03-30 19:24:03 227

原创 最长回文字串 (LEETCODE: Longest Palindromic Substring)

根据回文的特征,从字符串中某个位置(或某两个位置)为中心,向两边开始分析。直至找到最长的回文串。  string longestPalindrome(string s){//中心扩展法 int maxlen; int prev; int next; string result; maxlen = 0; //回文串为奇数时 for

2016-03-29 16:32:52 631

原创 LeetCode16. 3Sum Closest

Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exact

2016-03-29 16:21:44 204

原创 Leetcode 14. Longest Common Prefix

Write a function to find the longest common prefix string amongst an array of strings.题目大意:寻找一个字符串数组的最长共同前缀并返回此前缀。分析:前缀不会超过字符class Solution {public: string longestCommonPrefix(vector& strs)

2016-03-29 11:10:55 220

原创 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). Fin

2016-03-29 09:45:40 245

原创 leetcode4: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 (m+n)).题目大意就是给定两个长度分别为m、n的有序数组,求他们

2016-03-26 21:31:21 202

原创 BST的基本操作

// BST.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include #include #include #include using namespace std;typedef struct TreeNode{ int val; TreeNode *leftChild; TreeNode *rightChild; Tre

2016-03-25 21:00:44 666

原创 typedef void (*Fun) (void) 的理解——函数指针——typedef函数指针

上面介绍得是我们常用的比较简单的typedef的用法,下面首先介绍一下函数指针。//定义一个指针变量p,根据形式1函数指针的形式//我们可以知道他是指向一个参数为Int,返回类型为//char的函数指针char (*p) (int)函数指针的形式:形式1:返回类型(*函数名)(参数表)

2016-03-25 16:06:58 63614 26

原创 leetcode:Kth Smallest Element in a BST

Given a binary search tree, write a function kthSmallest to find the kth smallest element in it.Note: You may assume k is always valid, 1 ≤ k ≤ BST's total elements./** * Definition for a

2016-03-25 15:40:57 233

原创 Leetcode 219. Contains Duplicate II

Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between i and jis at most k.S

2016-03-22 16:52:22 332

原创 leetcode--258. Add Digits

Leetcode-258 addDigitsGiven a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like: 3 + 8 = 11,

2016-03-21 18:48:02 241

原创 Longest Substring Without Repeating Characters(leetcode)

12345678910111213141516171819202122leetcode学习8位二进制,总共有256个字符,不仅仅是我们常见的26个字母。intlengthOfLon

2016-03-21 16:14:45 278

原创 c++ + opencv + linux下加载文件(图片或级联分类器)路径的问题

之前在linux下做opencv中的函数的实验,经常会遇到无法打开函数中需要使用的图片,或者是无法加载opencv自带的级联分类器,运行的时候就会报出如下错误,其中,无法加载图片会爆如下得到错误:OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /home/cug507zy/open

2016-03-21 16:13:52 1210

转载 欢迎使用CSDN-markdown编辑器

欢迎使用Markdown编辑器写博客本Markdown编辑器使用StackEdit修改而来,用它写博客,将会带来全新的体验哦:Markdown和扩展Markdown简洁的语法代码块高亮图片链接和图片上传LaTex数学公式UML序列图和流程图离线写博客导入导出Markdown文件丰富的快捷键快捷键加粗 Ctrl + B 斜体 Ctrl + I 引用 Ctrl

2016-03-21 16:09:00 206

原创 首个重复字符,首个非重复字符(哈希表)

牛客网题目:于一个字符串,请设计一个高效算法,找到第一次重复出现的字符。给定一个字符串(不一定全为字母)A及它的长度n。请返回第一个重复出现的字符。保证字符串中有重复字符,字符串的长度小于等于500。测试样例:"qywyer23tdd",11返回:y类似的,如果题目要求返回首个非重复字符,都是利用哈希表来解决,建立字符-字符出现的频率键值对。由于

2016-03-16 16:21:27 916

原创 二分查找(返回目标元素的第一个位置、最后一个位置)

二分查找是针对有序数组的查找算法。一般意义上的二分查找,往往返回给我们的是目标元素在排序数组中出现的一个随机的位置,但是在很多时候,我们却是需要目标元素的第一个和最后一个位置,才有意义。本文分别针对最基础的二分查找、返回目标元素的第一个位置、返回目标元素的最后一个位置的进行的代码实现。class BinarySearch {public:    int getPos(vector A,

2016-03-16 11:23:39 8481 4

转载 动态规划:从新手到专家

转载地址:http://bbs.chinaunix.net/thread-4094539-1-1.html动态规划:从新手到专家前言我们遇到的问题中,有很大一部分可以用动态规划(简称DP)来解。 解决这类问题可以很大地提升你的能力与技巧,我会试着帮助你理解如何使用DP来解题。 这篇文章是基于实例展开来讲的,因为干巴巴的理论实在不好理解。注意:如果你对于其中某一节已经了解

2016-03-14 15:29:19 375

原创 链表的回文结构

题目要求:对于一个链表,请设计一个时间复杂度为O(n),额外空间复杂度为O(1)的算法,判断其是否为回文结构。给定一个链表的头指针A,请返回一个bool值,代表其是否为回文结构。保证链表长度小于等于900。测试样例:1->2->2->1返回:true思路:判断一个链表是不是回文数,要求O(n)时间  1. 使用2个指针,快慢指针各一个,每次快

2016-03-11 20:55:10 1656 1

转载 C++指针加整数、两个指针相减的问题

考虑如下问题:1     char a[20];2     int *ptr = (int *)a;3     ptr++;第3句ptr++实际为ptr右移一个int空间(即4个字节)的距离,此时ptr指向a[4]。若第3句改为int *p = ptr + 2;则p指向a[8]这里说明当指针加整数时,指针向后偏移的

2016-03-11 17:52:06 665

原创 栈的压入、弹出序列(剑指offer面试题)

问题描述:输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否为该栈的弹出顺序。假设压入栈的所有数字均不相等。例如序列1,2,3,4,5是某栈的压入顺序,序列4,5,3,2,1是该压栈序列对应的一个弹出序列,但4,3,5,1,2就不可能是该压栈序列的弹出序列。剑指offer书上分析总结的规律:如果下一个弹出的数字刚好的栈顶数字,那么直接弹出,如果下一个弹出的数字不在栈顶,我们把压

2016-03-01 15:29:45 1009

空空如也

空空如也

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

TA关注的人

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