自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(386)
  • 资源 (3)
  • 收藏
  • 关注

转载 [LeetCode] Gas Station 加油站问题

相关问题1:https://blog.csdn.net/jiyanfeng1/article/details/39361485There areNgas stations along a circular route, where the amount of gas at stationiisgas[i].You have a car with an unlimited gas ...

2019-05-03 21:17:45 607

原创 [LeetCode] Rectangle Area II

相关问题1:https://blog.csdn.net/jiyanfeng1/article/details/41616781问题描述和解答:https://leetcode.com/articles/rectangle-area-ii/

2019-05-02 22:46:03 327

转载 [LeetCode] Image Overlap 图像重叠

Two imagesAandBare given, represented asbinary, square matrices of the same size. (A binary matrix has only 0s and 1s as values.)We translate one image however we choose (sliding it left, righ...

2019-05-02 22:32:34 562

转载 C++ Memory Management C++ 内存管理

ProblemC++ has several distinct memory areas where objects and non-object values may be stored, and each area has different characteristics.Name as many of the distinct memory areas as you can. Fo

2015-08-12 04:41:23 992

原创 [LeetCode] 01矩阵中最大正方形 Maximal Square

Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and return its area. For example, given the following matrix:1 0 1 0 01 0 1 1 11 1 1 1 11 0 0 1 0Re

2015-08-04 03:48:44 8957

原创 [LeetCode] Shortest Palindrome I

相关问题1:最长回文子串相关问题2:Minimum insertions to form a palindromeGiven a string S, you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest pal

2015-08-03 11:13:52 889

原创 Minimum insertions to form a palindrome

给你一个字符串S,插入一些字符,把 S 转换成一个回文字符串。例如:ab: Number of insertions required is 1. babaa: Number of insertions required is 0. aaabcd: Number of insertions required is 3. dcbabcdabcda: Number of inser

2015-08-03 11:12:18 1032

原创 [LeetCode] Count Complete Tree Nodes

Given a complete binary tree, count the number of nodes.思路:找到最左边的节点和最右边的节点,如果二者高度一致,那么说明最后一层是满的,返回2^h-1。否则,递归下去。代码: int countNodes(TreeNode* root) { if(!root) return 0;

2015-08-03 10:16:06 605

原创 [LeetCode] Fraction to Recurring Decimal

Given two integers representing the numerator and denominator of a fraction, return the fraction in string format. If the fractional part is repeating, enclose the repeating part in parentheses. For e

2015-08-03 06:44:33 598

原创 [LeetCode] Best Time to Buy and Sell Stock VI

相关问题:给你一个数组,数组的每个元素表示每天的stock价格,你最多可以进行k次交易,两次交易不能在时间上重叠,也就是说,你必须先卖掉股票,才能再买入股票。求可以获得的最大利润。 思路:利用动态规划。这里我们需要两个递推公式来分别更新两个变量local和global,参见网友Code Ganker的博客,我们其实可以求至少k次交易的最大利润。我们定义local[i][j]为在到达第i

2015-08-03 05:16:40 555

原创 [LeetCode] Best Time to Buy and Sell Stock III

相关问题:[LeetCode] Best Time to Buy and Sell Stock II给你一个数组,数组的每个元素表示每天的stock价格,你最多可以进行2次交易,两次交易不能在时间上重叠,也就是说,你必须先卖掉股票,才能再买入股票。求可以获得的最大利润。该问题还可以扩展为:把最多2次交易的条件,改成最多k次交易。相关问题:

2015-08-03 03:34:52 527

原创 Find maximum repeating number

给你一个长度是n的整数数组,数组中数字的范围是 [0, k-1] ,  k 满足 k思路1:用计数排序的方法,把数组排序,然后找到最大的重复出现的数字。思路2:假如给定arr[] = {2, 3, 3, 5, 3, 4, 1, 7}, k = 8, n = 8。那么,Iterate though input array arr[], for every

2015-08-03 02:32:47 478

原创 [LeetCode] Insert Interval 插入区间

Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary). You may assume that the intervals were initially sorted according to their start times.Exam

2015-08-02 23:18:36 582

原创 字符串旋转-回文字符串

相关问题:最长回文子串给你一个字符串,求问,这个字符串旋转之后是不是一个回文字符串?例如:给你字符串 str = "aaaab",那么str旋转之后可以得到 str_new = "aabaa",是个回文字符串。思路:可以把str和str接起来,得到“aaaabaaaab”,然后对"aaaabaaaab"求最长回文字符子串。利用Machester算法,复杂度是O(n).

2015-08-02 03:29:44 665

原创 Egg Drop 扔鸡蛋

假设有 n=2 个完全一样的鸡蛋, 有 k=36 层楼。 存在一个楼层 m,把鸡蛋从低于m的楼层扔下去的时候,鸡蛋不会摔破;把鸡蛋从高于等于m的楼层扔下去的时候,鸡蛋会摔破。题目要求,找出临界楼层m,并且扔鸡蛋的次数要做到最少。思路:最简单的方法是,从第 1 层往上,一层一层 的扔鸡蛋,直到鸡蛋摔碎。这样需要扔鸡蛋 m 次。下面用递归的方法解决该问题。假设鸡蛋从 x 层扔下去。(1)如

2015-08-01 23:44:20 2611 1

原创 [LeetCode] 零的个数 number of trailing zeros

给定一个整数 n,求出n的阶乘的尾零的个数。思路:只有2和5相乘才能得到一个尾零。如果2^2和5^2相乘,能得到两个尾零。。。代码: int numZeros(int num) { int count = 0; if (num < 0) { cout<<"Factorial is not defined for < 0"; return 0; } for

2015-07-31 12:30:33 1654

原创 后缀树和前缀树

给你一个很长的字符串 s,和一堆短字符串 T = {t1, t2, ...}。 设计一个高效的算法,确定T 里的每个字符串是不是 s 的子串。思路:先对字符串s构建一个后缀树,然后看看t1,t2...,是不是s的一个后缀的前缀。构建后缀树和查找后缀树的前缀都可以用递归的思路来解决。具体代码如下:public class SuffixTree { SuffixTreeNode ro

2015-07-31 11:12:05 807

翻译 最大重叠区间数目 Maximum number of overlapping intervals

最大重叠区间数目 Maximum number of overlapping intervals有一个party,许多人来参加。一个记录仪记录下了每个人到达的时间 s_i 和离开的时间 e_i ,也就是说每个人在party的时间为 [ s_i, t_i ]。求出这个party 同一时刻最多接纳了多少人。例如:Input: arrl  [] = {1, 2, 9, 5, 5}     

2015-07-21 23:40:38 5061

原创 Pancake sorting 煎饼排序

Pancake sorting 煎饼排序

2015-07-21 12:04:59 2961

原创 幸运数字 2

幸运数是波兰数学家乌拉姆命名的。它采用与生成素数类似的“筛法”生成。首先从1开始写出自然数1,2,3,4,5,6,....。1 就是第一个幸运数。我们从2这个数开始。把所有序号能被2整除的项删除,变为:1 _ 3 _ 5 _ 7 _ 9 ....把它们缩紧,重新记序,为:1 3 5 7 9 .... 。这时,3为第2个幸运数,然后把所有能被3整除的序号位置的数删去。注意,是序号位置,不

2015-07-21 10:12:14 1306

原创 幸运数字 1

定义“幸运号码”是十进制表示中只包含数字6和8的那些号码,比如68,666,888。定义“近似幸运号码”是能被任意一个幸运号码整除的那些号码,比如6,8,12,16。现在问对闭区间[a, b],“近似幸运号码”的个数。输入数据是一行,包括2个数字a和b,1比如输入:1 101234 4321输出2809

2015-07-21 10:10:18 1667

原创 非零比特的个数 count the number of bits

Counting bits set, Brian Kernighan's wayunsigned int v; // count the number of bits set in vunsigned int c; // c accumulates the total bits set in vfor (c = 0; v; c++){ v &= v - 1; // clear the

2015-07-16 23:25:34 1514

原创 求三个数的中数 find median of three numbers

int medianOfThreeNums(int A, int B, int C){ if ((A - B) * (C - A) >= 0) return A; else if ((B - A) * (C - B) >= 0) return B; else return C; }

2015-07-16 11:31:22 1216 1

原创 船只数目 number of boats

给定一个数组 float arr [ N ] ,数组中每个数代表一个人的体重。这些人要过河,一条船最多载两个人,最大载重为 W 公斤。把这些人运过河,最少要多少条船?解法:先对数组排序,然后设置两个指针,idx1 和 idx2 ,idx1=0,idx2=N-1。 如果 arr[idx1] + arr[idx2] 如果 arr[idx1] + arr[idx2] > W,  那么船数

2015-07-16 08:36:03 562

原创 The kth largest element in max-heap 最大堆的第k大元素

给定一个最大堆,找出第k大的节点。解法:建一个最小堆 minHeap来解决此题.    1 取最大堆的根节点,放入minHeap;    2 移除minHeap的根节点,并把该根节点在最大堆的两个子节点插入minHeap(插入过程保证heap的性质);    3 回到1.2 步。minHeap的节点数在不断增加,但是不会超过2k。minHeap插入节点的复杂度是

2015-07-16 02:59:03 1556 1

原创 Find duplicates in an array

Find duplicates in an array of length n. The array values are in the range of [1, n-1].思路:可以用bucket sort 先对数组排序,然后扫描排序后的数组,即可知道重复值。相关问题:[LeetCode] 找到第一个不存在的正整数 First Missing Positive

2015-07-15 06:29:48 505

原创 从二叉树中随机选择节点

给定一个二叉树,要求随机选择树上的一个节点。解法:遍历树的过程中,随机选择一个节点即可。具体做法参看:从输入流中随机抽取m个元素

2015-07-15 05:58:53 1692

原创 失恋阵线同盟

[description] 莉莉安女学园的少女们,今天也带着无垢的笑容,穿过等身高的校门。但是,鲜为人知的是,每个少女都暗恋着另一位同学。而害羞的少女们都没有对对方表白。也许是怕说出以后,得到的回答不是自己希望听到的吧。毕竟,大多数人是单恋,而像A喜欢B,B喜欢C,C喜欢D,。。。,F喜欢G,G又喜欢A这种情况也是很常见的。假设没有人自恋。一些少女自发组成了“失恋阵线同盟”,目的为了互相鼓励,得到

2015-02-24 00:17:26 718

原创 Insert into a sorted circular linked list 环状链表 插入节点

给定一个排好序的环状链表,将一个节点插入到环状链表中。例如,给定如下的环状链表,将数字7插入到链表中,得到如下的环状链表。

2015-02-10 04:55:54 1029

原创 [LeetCode] Remove Nth Node From List 删除链表的第N个节点

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 the second node from the end, the linked lis

2015-02-10 03:27:45 530

原创 [LeetCode] 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. You may

2015-02-10 00:11:17 485

原创 [LeetCode] Reverse Nodes in k-Group

Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is. Y

2015-02-09 13:48:47 553

原创 [LeetCode] Insertion Sort List

Sort a linked list using insertion sort./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * };

2015-02-09 12:06:31 447

原创 生成随机数, random 5, random 7

给定一个范围是1到5的随机整数生成器,设计一个范围是1到7的随机整数生成器。解法:int rand7(){ int vals[5][5] = { { 1, 2, 3, 4, 5 }, { 6, 7, 1, 2, 3 }, { 4, 5, 6, 7, 1 }, { 2, 3, 4, 5, 6 }, {

2015-02-05 12:13:21 4138

原创 Find the distance between two nodes

找出二叉树中两个结点间的距离.下面的算法的思路和lowest common ancestor的思路是一样的。适用的情况是,给定的两个节点都存在于二叉树上,而且一个节点不能是另外一个的父节点。#include #include using namespace std;struct Node{ int data; Node* left; Node* right; Nod

2015-01-17 05:29:05 651

原创 Find common characters in a set of strings

Find the number of letters common in a given set of strings. Note that the given set of strings might have duplicates.思路例如给定如下3个字符串:aaaabbchdjnffbccgdaabstep 1:对每个字符串都去重处理。step 2:用

2015-01-17 00:43:55 588

原创 Light is falling on a tree from left side you have to find all the nodes on which this light will fa

思路:所求节点就是层序遍历中,每一层的第一个节点。#include #include #include // pairusing namespace std;struct Node{ int data; Node* left; Node* right;};vector lightFall(Node* root){

2015-01-16 06:26:21 1074

原创 [LeetCode] Determine if two rectangles overlap

Given two axis-aligned rectangles A and B. Write a function to determine if the two rectangles overlap.从问题的反面入手,先看看什么情况下两个长方形不重叠。不重叠的条件是:( P2.y P4.y || P2.x P4.x )直接给代码:struct Poin

2015-01-15 06:09:10 1054

原创 Find subarray with given sum

Given an unsorted array of nonnegative integers, find a continous subarray which adds to a given number. Examples:Input: arr[] = {1, 4, 20, 3, 10, 5}, sum = 33Ouptut: Sum found between indexes 2 a

2015-01-15 05:32:58 782

原创 [LeetCode] Largest Number

Given a list of non negative integers, arrange them such that they form the largest number. For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330. Note: The result may be very lar

2015-01-15 00:57:19 1052

Monte carlo模拟的Mathematica代码

本文件是用Mathematica代码编写的Monte carlo模拟。 包含均匀分布,指数分布,以及均匀分布在圆和球面上的点。

2010-04-10

网格搜索法--求公切线算法

网格搜索法--求公切线算法。Mathematica程序。

2009-07-08

北邮通信电子电路自测题

这是本人在北邮学习期间,搜集的通信电子电路自测题。老师给的。很有价值。

2009-07-08

空空如也

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

TA关注的人

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