![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
程序员代码面试指南
文章平均质量分 80
LUCASYAN个
这个作者很懒,什么都没留下…
展开
-
leetcode 239. Sliding Window Maximum 双端队列 滑动窗口最大值
Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window原创 2017-09-04 15:25:15 · 843 阅读 · 0 评论 -
字符串(代码面试指南)
1、字符串中数字子串求和【题目】 给定一个字符串str,求其中全部数字串所代表的数字之和。【要求】 1、忽略小数点字符,例如"A1.3",其中包含两个数字1和3。 2、如果紧贴数字子串的左侧出现字符'-',当连续出现的数量为奇数时,则数字为负数,连续出现的数量为偶数时,则数字为正数。例如,"A-1BC--12",其中包含数字是-1和12。【举例原创 2017-08-26 14:40:45 · 182 阅读 · 0 评论 -
priority_queue 用法与编程题目
#include 头文件priority_queue<Type, Container, Functional>默认是大顶堆greaterpriority_queueint, vectorint>, greaterint> > q;加入 q.push();弹出 q.pop();队头 q.top();对于自定义类型,则必须自己重载 operat原创 2017-08-31 11:24:09 · 373 阅读 · 0 评论 -
判断字符数组中是否所有的字符只出现了一次(左程云)非递归堆排序实现
【题目】 给定一个字符类型数组chas,判断chas中是否所有的字符都只出现过一次。【基本思路】 一.时间复杂度为O(N)的算法。 使用哈希表,记录每个字符出现的频数,如果发现字符的频数不为1,直接返回False。 二.时间复杂度为O(NlogN),空间复杂度为O(1)的算法。 1.先将数组排序,再判断当前字符是否等于前一个原创 2017-08-29 17:15:14 · 520 阅读 · 1 评论 -
在有序但含有空的数组中查找字符串
比如给定一个字符串数组,“”,“ab”,"ab","","","","xx","yy","zz",查找ab字符串最左边的位置就是1,而不是2。如果要找的字符串是空,或者根本没有找到,就返回-1思路采用二分法,但是这里和普通二分不同,要进行判断设要找的字符串为str,start=0,end等于字符串数组最后一个位置如果当前mid处值等于要找的,这时候传给全局变量Pos原创 2017-08-29 20:27:07 · 462 阅读 · 0 评论 -
416. Partition Equal Subset Sum 类似最小不可组成和
Given a non-empty array containing only positive integers, find if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal.Note:Each of the array原创 2017-09-16 08:59:39 · 237 阅读 · 0 评论 -
10. Regular Expression Matching 字符串匹配 左程云
Implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the entire input st原创 2017-09-17 19:39:23 · 501 阅读 · 1 评论 -
蓄水池算法
基本概念参考程序员面试指南 这种方法关键是理解思想,实际的代码非常简单。leetcode变形题398. Random Pick IndexGiven an array of integers with possible duplicates, randomly output the index of a given target number. You can assume t原创 2017-09-26 12:50:57 · 1367 阅读 · 0 评论 -
525. Contiguous Array
给定一个数组,只包含0和1,求最大的子数组长度,使得0和1的数目相等。思路:这个问题可以转变成560 最长区间和为给定值这道题。只需要将0改成-1.建立一个哈希标保存,累加和是一个值的最左位置。当前位置i的累加和是x,那么只要找到最左边累加和也是x的位置j,那么(j,i]的累加和就是0,说明0和1的数目相等。这个题注意两点:1、加和为0的位置设置成-1;2、由于map的默认值是原创 2017-09-12 14:41:00 · 154 阅读 · 0 评论