![](https://img-blog.csdnimg.cn/20201014180756913.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
coding
yinger_0131
这个作者很懒,什么都没留下…
展开
-
约瑟夫问题两种解决方式
Josephus 约瑟夫 问题 假设n个竞赛者排成一个环形,依次顺序编号1,2,…,n。从某个指定的第1号开始,沿环计数,每数到第m个人就让其出列,且从下一个人开始重新计数,继续进行下去。这个过程一直进行到所有的人都出列为止。最后出列者为优胜者。解法一: 递推公式 f[1]=0; f[i]=(f[i-1]+m)%i; (i>1)#include<i...原创 2018-04-10 09:56:05 · 504 阅读 · 0 评论 -
LeetCode(90)-Subsets II 子集合之二
Given a collection of integers that might contain duplicates, S, return all possible subsets.Note:Elements in a subset must be in non-descending order. The solution set must not contain duplicate...原创 2018-05-04 01:17:07 · 107 阅读 · 0 评论 -
LeetCode(1)--two sum两数之和
Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution.Example:Given nums = [2, 7...原创 2018-05-04 14:35:40 · 81 阅读 · 0 评论 -
LeetCode(118)-pascal triangle(杨辉三角)
Given numRows, generate the first numRows of Pascal’s triangle.For example, given numRows = 5, Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ]具体生成算是:每一行的首个和结尾一个数字都是1,...原创 2018-05-18 23:39:27 · 172 阅读 · 0 评论 -
LeetCode(15)-3sum 三数之和
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:Elements in a triplet (a,b,c) must b...原创 2018-05-06 15:30:23 · 106 阅读 · 0 评论 -
LeetCode(145)-二叉树后序遍历(递归、非递归)
import java.util.ArrayList;import java.util.Stack;public class l145_tree_postorder { class TreeNode{ int val; TreeNode left; TreeNode right; TreeNode(int x){ ...原创 2018-05-20 00:46:52 · 694 阅读 · 0 评论 -
酷家乐笔试
题目(类似): s = “3[a]2[bc]”, return “aaabcbc”. s = “3[a2[c]]”, return “accaccacc”. #include <iostream>using namespace std; string decode(string s, int &k) { string res = ""; ...原创 2018-04-29 00:23:10 · 2139 阅读 · 0 评论 -
LeetCode(143)-reorder-list
Given a singly linked list L: L 0→L 1→…→L n-1→L n, reorder it to: L 0→L n →L 1→L n-1→L 2→L n-2→…You must do this in-place without altering the nodes’ values.For example, Given{1,2,3,4}, reorder ...原创 2018-05-21 00:01:32 · 135 阅读 · 0 评论 -
一道从室友那儿偷来的51信用卡笔试题-判断字符串A是否包含字符串B
目前思路是分别扫描两个字符串得到两个map boolean judge(String str1,String str2){ HashMap<Character,Integer> map1=new HashMap<>(); HashMap<Character,Integer> map2=new HashMap<...原创 2018-05-07 20:34:25 · 164 阅读 · 0 评论 -
LeetCode(150)-Evaluate Reverse Polish Notation 计算逆波兰表达式
Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expression.Some examples:[“2”, “1”, “+”, “3”, ...原创 2018-05-15 12:59:13 · 145 阅读 · 0 评论 -
酷家乐一面-停车场记录
编写一个程序,做一个简易的停车场使用数据记录仪。此程序能够监听命令行输入,命令行可以输入三类命令:(下述命令中的参数值均为举例,实际使用中不会限定数值) 1: checkin –t=225959 –n=AT4257 2: checkout –t=233000 –n=AT4257 3: listrecord –all 4: listrecord –n=AT4257其中第一条命令代表车...原创 2018-05-15 23:57:36 · 1374 阅读 · 0 评论 -
LeetCode(149)-Max Points on a Line 共线点个数
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. 求最大的共线点的个数public class l149_maxpoints_in_line { static class Point{ int x; in...原创 2018-05-17 01:18:34 · 185 阅读 · 0 评论 -
剑指-和为s的连续正数序列
题目描述 小明很喜欢数学,有一天他在做数学作业时,要求计算出9~16的和,他马上就写出了正确答案是100。但是他并不满足于此,他在想究竟有多少种连续的正数序列的和为100(至少包括两个数)。没多久,他就得到另一组连续正数和为100的序列:18,19,20,21,22。现在把问题交给你,你能不能也很快的找出所有和为S的连续正数序列? Good Luck! 输出描述: 输出所有和为S的连续正数序...原创 2018-04-21 16:12:26 · 135 阅读 · 0 评论 -
刷题-dp经典问题-背包问题
#include <iostream>using namespace std;int v[10000];int w[10000];int bag(int n,int W){ int F[n+1][W+1]; for(int i=0;i<=n;i++) { for(int j=0;j<=W;j++){ F...原创 2018-04-10 09:56:55 · 209 阅读 · 0 评论 -
算法-贪心算法-活动安排
活动安排问题活动安排问题就是要在所给的活动集合中选出最大的相容活动子集合,是可以用贪心算法有效求解的很好例子。该问题要求高效地安排一系列争用某一公共资源的活动。贪心算法提供了一个简单、漂亮的方法使得尽可能多的活动能兼容地使用公共资源。设有n个活动的集合E={1,2,…,n},其中每个活动都要求使用同一资源,如演讲会场等,而在同一时间内只有一个活动能使用这一资源。每个活动i都有一个要求使用该...原创 2018-04-10 10:55:57 · 407 阅读 · 0 评论 -
华为笔试及面试经历
1.大数相乘#include<iostream>#include<cstdio>#include<math.h>using namespace std;int multiply (const std::string sA,const std::string sB, std::string &res){ /* 在这里实现功能 *...原创 2018-04-22 10:43:40 · 7711 阅读 · 0 评论 -
剑指-调整数组顺序
题目描述 输入一个整数数组,实现一个函数来调整该数组中数字的顺序,使得所有的奇数位于数组的前半部分,所有的偶数位于位于数组的后半部分,并保证奇数和奇数,偶数和偶数之间的相对位置不变。 1.空间换时间#include <iostream>#include <algorithm>#include <vector>using namespace std;...原创 2018-04-22 14:23:41 · 231 阅读 · 0 评论 -
剑指-链表中倒数第K个节点
主要要增强代码鲁棒性,考虑边界条件#include <iostream>using namespace std;struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { }};ListNode* FindKthTo...原创 2018-04-22 17:08:21 · 73 阅读 · 0 评论 -
刷题-DP-跳跃问题
输入n表示数组元素个数; 数组中的每个元素表示在该位置能跳跃的最大步数。 求最小跳跃步数#include <iostream>#include<math.h>#include<cstdio>#include<algorithm>using namespace std;#define N 1000int A[N];int...原创 2018-04-12 23:17:50 · 300 阅读 · 0 评论 -
剑指-顺时针打印矩阵
题目描述 输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字,例如,如果输入如下矩阵: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 则依次打印出数字1,2,3,4,8,12,16,15,14,13,9,5,6,7,11,10./* 顺时针打印矩阵 */#include <iostream>#include<vector...原创 2018-04-22 22:33:54 · 95 阅读 · 0 评论 -
爱奇艺笔试-1
只会有两种重量的玩偶,最后找到数量为1的那种玩偶对应的序号。#include <iostream>#include<cstdio>#include <algorithm>using namespace std;int a[1000];int b[1000];int main(){ int n,i,x; cin>>...原创 2018-04-19 22:34:10 · 258 阅读 · 0 评论 -
快手笔试题1
/* 第一行输入n,m 输入n个字符串 输入m个字符串 若m中的字符串在n中出现过,输出yes,否则输出no */#include <iostream>#include <string>#include<cstdio>#include <vector>using namespace std;int main(){ in...原创 2018-04-21 10:21:06 · 2604 阅读 · 0 评论 -
剑指offer-连续子数组最大和
/* HZ偶尔会拿些专业问题来忽悠那些非计算机专业的同学。今天测试组开完会后,他又发话了:在古老的一维模式识别中,常常需要计算连续子向量的最大和,当向量全为正数的时候,问题很好解决。但是,如果向量中包含负数,是否应该包含某个负数,并期望旁边的正数会弥补它呢?例如:{6,-3,-2,7,-15,1,2,2},连续子向量的最大和为8(从第0个开始,到第3个为止)。你会不会被他忽悠住?(子向量的长度至...原创 2018-04-21 11:27:24 · 127 阅读 · 0 评论 -
LeetCode(138) Copy List with Random Pointer 拷贝带有随机指针的链表
A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list.public class l138_copy_list_with_r...原创 2018-05-24 16:59:55 · 287 阅读 · 0 评论