• 等级
  • 65805 访问
  • 155 原创
  • 314 转发
  • 20004 排名
  • 19 评论
  • 18 获赞

全排列

1 递归回溯的那几点要素   void permutation(string &str,int k){ if(k==(str.size())){ cout<<str<<endl; return ; } for(int i=k;i<str.size();++i){ swap(str[k],str[i]); permutation(s...

2019-01-19 17:56:04

Group Anagrams 群组错位词

Given an array of strings, group anagrams together. Example: Input: ["eat", "tea", "tan", "ate", "nat", "bat"], Output: [ ["ate","eat","tea"], ["nat"

2019-01-19 17:00:03

Top K Frequent Elements 前K个高频元素

    Given a non-empty array of integers, return the k most frequent elements. Example 1: Input: nums = [1,1,1,2,2,3], k = 2 Output: [1,2] Example 2: Input: nums = [1], k = 1 Output: [1] Note...

2019-01-19 16:45:15

算法——错排问题

错排问题 错排问题 就是一种递推式,不过它比较著名且常用,所以要熟记! 方法一:  n各有序的元素应有n!种不同的排列。如若一个排列式的所有的元素都不在原来的位置上,则称这个排列为错排。任给一个n,求出1,2,……,n的错排个数Dn共有多少个。 递归关系式为:D(n)=(n-1)(D(n-1)+D(n-2)) D(1)=0,D(2)=1 可以得到: 错排公式为 f(n) = n![1-1/1!+...

2019-01-19 16:07:26

数组2个的交集

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 resul...

2019-01-19 14:43:17

二叉树转换为双向链表

  解题思路: 1.核心是中序遍历的非递归算法。 2.修改当前遍历节点与前一遍历节点的指针指向。 * struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), righ...

2019-01-19 14:14:51

小孩分糖问题

问题描述 There are N children standing in a line. Each child is assigned a rating value. You are giving candies to these children subjected to the following requirements: Each child must have at least o...

2019-01-19 14:04:44

队列中取最大值操作问题用栈实现

问题: 假设有这样一个拥有3个操作的队列: 1. EnQueue(v): 将v加入队列中 2. DeQueue(): 使队列中的队首元素删除并返回此元素 3. MaxElement: 返回队列中的最大元素 设计一种数据结构和算法,让MaxElement操作的时间复杂度尽可能地低。   思路: (1)用两个栈设计一个新的数据类型(数据类型定义为MyStack),其中一个栈用来存放数据,另一个...

2019-01-19 13:29:53

滑动窗口中的最大值

题目描述 题目描述 给定一个数组和滑动窗口的大小,找出所有滑动窗口里数值的最大值 例如,如果输入数组{2,3,4,2,6,2,5,1}及滑动窗口的大小3 那么一共存在6个滑动窗口, 他们的最大值分别为{4,4,6,6,6,5}; 针对数组{2,3,4,2,6,2,5,1}的滑动窗口有以下6个 {[2,3,4],2,6,2,5,1},最大值4 {2,[3,4,2],6,2,5,1},最大...

2019-01-19 12:18:48

有序数组中的平方个数

  题目如下: 给你一个有序整数数组,数组中的数可以是正数、负数、零,请实现一个函数,这个函数返回一个整数:返回这个数组所有数的平方值中有多少种不同的取值。举例: nums = {-1,1,1,1}, 那么你应该返回的是:1。因为这个数组所有数的平方取值都是1,只有一种取值 nums = {-1,0,1,2,3} 你应该返回4,因为nums数组所有元素的平方值一共4种取值:1,0,4,...

2019-01-18 23:47:56

pow 的实现

要点: 1 n的正负数 2 double 类型的 class Solution { public: double pow(double x, int n) { if(equal(x,0.0)&&n<0){ return 0; } double res=1; ...

2019-01-18 23:28:02

跳跃游戏2

Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position. Your goal is to...

2019-01-18 23:22:37

mysql数据库表清空后id如何从1开始自增

环境:          数据库:mysql 我们的数据库表中经常会使用id自增,但是每次清空表后id并不是从1开始计数,总是接着之前的进行自增,那么解决呢? 使用mysql的truncate命令,用法:truncate table 表名; 这样表的id自增就会变回从1开始自增了。 备注:该操作会清空您宝贵的数据库,我想题目已经说的够清楚了,请谨慎操作 -----------------...

2019-01-18 11:56:37

atoi的实现

class Solution { public: int atoi(const char *str) { if(str==NULL){ //1 return 0; } int i=0; long long res=0; while(isspace(str[i])){//2 ...

2019-01-18 08:39:40

Jump Game 跳跃游戏

Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position. Determine if yo...

2019-01-18 08:35:58

Rotate Image 旋转图像

You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). Note: You have to rotate the image in-place, which means you have to modify the input 2D matrix d...

2019-01-18 08:19:52

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 exac...

2019-01-18 07:45:03

Trapping Rain Water 收集雨水

  Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. For example, Given [0,1,0,2,1,0,1,3,2,1,2,1],...

2019-01-18 07:12:24

House Robber III 打家劫舍之三

The thief has found himself a new place for his thievery again. There is only one entrance to this area, called the "root." Besides the root, each house has one and only one parent house. After a tour...

2019-01-17 23:16:58

House Robber II 打家劫舍之二

You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are arranged in a circle. That means the first house is ...

2019-01-17 23:10:26

江上渔者21号

关注
  • 嵌入式/硕士
  • 中国 河北省 唐山市
奖章
  • 持之以恒