自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 常见面试题及其解答--问题摘自程序员面试笔试宝典(未完待续)

(1)extern的作用。这个应该分为才C和C++中的区别。C语言中extern声明的函数和变量可以被该文件外部的模块引用,C++中除了该作用以外,还可以声明extern “C”用来表示一段代码编译连接的方法为C语言的方法。1.extern是C/C++语言中声明函数和全局变量作用范围的关键字,改关键字告诉编译器,其声明的函数和变量在本模块或其他模块中使用,通常,在模块的头文件中,对本模块提

2016-04-21 11:52:45 479

原创 LeetCode 344. Reverse String

Write a function that takes a string as input and returns the string reversed.Example:Given s = "hello", return "olleh".AC代码: string reverseString(string s) { string ans;

2016-04-24 17:49:52 960

原创 LeetCode 189. Rotate Array

Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].Note:Try to come up as many solutions as

2016-04-24 17:37:54 202

原创 LeetCode 61. Rotate List

Given a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL.AC代码如下:ListNode* rotateRight(Li

2016-04-24 17:33:52 366

原创 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 be:bo

2016-04-24 15:57:45 252

转载 Trie树详解及其应用

一、知识简介        最近在看字符串算法了,其中字典树、AC自动机和后缀树的应用是最广泛的了,下面将会重点介绍下这几个算法的应用。      字典树(Trie)可以保存一些字符串->值的对应关系。基本上,它跟 Java 的 HashMap 功能相同,都是 key-value 映射,只不过 Trie 的 key 只能是字符串。  Trie 的强大之处就在于它的时间复杂度。它的插入和

2016-04-18 11:16:31 301

原创 c++ stl set之顺序排序。

平时在用到map容器的时候,想到的只是他是存储键值对的,类似哈希表,但最近看剑指offer上的一道题目——寻找最小的K个数,才知道map还可以在定义的时候就定义了其排列顺序。首先看看标准map的定义:template < class T, // set::key_type/value_type class Compare

2016-04-17 11:33:07 10590

原创 求三个矩形的相交矩形。

金山WPS2016实习生招聘(武大宣讲会+现场笔试题)2016年4月11日晚上7:00-9:00参加的笔试。给定一个矩形结构体:struct Rect{ int x; int y; int w; int h};要求实现函数:Rect IntersectRect(const Rect &rectA,const Rect &rectA,const

2016-04-12 10:04:08 1433

原创 LeettCode 29. Divide Two Integers

Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.求两个整数相除的结果,不允许用到乘、除、求余操作。最简单的当然是以除数一个一个的加,知道最终超过哟被除数,这样做的话会超时。代码如下:int

2016-04-10 15:28:07 346

原创 LeetCode 25 reverse-nodes-in-k-group

解决这题之前,先看看这一题:Reverse  a linkedlist from positionm to n. Do itin-place andin one-pass.For example: Given 1->2->3->4->5->NULL,m = 2 and n= 4,return 1->4->3->2->5->NULL.Note: G

2016-04-10 11:13:59 391

转载 KMP字符串匹配,next数组的求解

对KMP算法只有了解,但一直对next数组的求解弄不明白,今天通过看书以及网上搜索相关资料,终于把这部分弄明白了。1.KMP算法的原理。-本部分内容转自:http://www.ruanyifeng.com/blog/2013/05/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm.html举例来说,有一个字符串"BBC ABCDAB ABCDAB

2016-04-10 10:07:16 2405 1

原创 京东2016笔试题

题目大致意思就是给定一个8×8的棋盘,给定两个点A,B,求从A到B需要走的最短步数,并打印最短路径。走的每一步的方向可以为左(L)、右(R)、上(U)、下(D)、左下(LD)、左上(LU)、右下(RD)、右上(RU)。确定A到B的路径时,优先走斜的的路径,然后走直的。比如从(5,1)到(8,8)需要的最短步数为7,分别为右上、右上、右上、上、上、上、上。即输入518

2016-04-08 21:18:01 3755

原创 LeetCode 28 . Implement strStr()

Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.这一题重点应该是考察KMP算法,我这里列出的两种算法都不是KMP算法,KMP算法都忘记了,先去研究研究,后面再补上KMP算法//暴力解法,时间复杂度超了int strStr(str

2016-04-08 09:51:28 217

原创 LeetCode 27. Remove Element

Given an array and a value, remove all instances of that value in place and return the new length.Do not allocate extra space for another array, you must do this in place with constant memory.

2016-04-07 22:23:35 224

原创 LeetCode 26 Remove Duplicates from Sorted Array

Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place with

2016-04-07 22:07:13 190

原创 [2016腾讯暑期实习在线笔试题]最长回文字符串

问题:求给定字符串s的回文(palindrome)子串中,长度最大的回文子串的长度。 回文(palindrome)是指从左往右读和从右往左读字符串,看到的字符串都是一样的。比如“cabbeaf”,回文子串包括”c”“aba”“abba”等,最长的子串是“abba”,长度为4. 程序输入:“cabbeaf” 程序输出:4这个和之前leetcode中求字符串的最长回文子串还有所不同,,

2016-04-07 20:40:05 1991

原创 LeetCode 23 Merge k Sorted Lists

上一篇写的是通过建立最小堆的方法合并,这里在网上看到了另一种思路。LeetCode 21 解决的是合并两个有序链表的问题,这里可以利用那种方法。ListNode* mergeKLists(vector& lists) { int length = lists.size(); if (length == 0) { return NULL

2016-04-02 11:07:45 273

原创 LeetCode 23. Merge k Sorted Lists

Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.思路:将每个链表的头结点取出来,建立一个最小堆,每次取堆顶元素(即K个链表中的最小值),然后将其合并到链表中,再将堆顶元素的下一个元素加入堆中,调整堆,使其满足最小堆,然后再取堆顶元素,如此反复,

2016-04-01 16:09:50 228

空空如也

空空如也

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

TA关注的人

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