![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法设计
鲁中地区有小雨
这个作者很懒,什么都没留下…
展开
-
Python 动态规划算法求解最长公共子序列
前言:在网上看到一道360的秋招真题,题目如下:仔细读题后发现这是一道求解最长公共子序列的问题,最好使用动态规划算法。题目大意:小B坐火车,从起点到终点的车站序列已知,期间他睡了两觉,到终点的时候还在睡,也就是说中间他醒了两次,这两次清醒的时间,有两个车站子序列,现在让我们分析这两段路是去的时候看到的,还是回来的时候看到的,来回都能看到,还是说压根不存在。思路:一共有四原创 2017-05-22 21:31:04 · 3134 阅读 · 0 评论 -
选举游戏(京东2016实习生真题)
题目描述 小东和其他小朋友正在玩一个关于选举的游戏。选举是通过投票的方式进行的,得票最多的人将获胜。小东是编号为1的候选者,此外还有其他的候选者参加选举。根据初步的调查情况,所有准备投票的小朋友都有一定的投票倾向性,小东如果要获得胜利,必须争取部分准备为其他候选人投票的小朋友。由于小东的资源较为有限,她希望用最小的代价赢得胜利,请你帮忙计算她最少需要争取的选票数。原创 2017-05-20 20:13:48 · 667 阅读 · 2 评论 -
每天一道算法题——奇偶数划分
要求:有一个整数数组,写一个函数,实现奇数奇数在左,偶数在右。例子:a[10] = {2,4,3,5,7,8,1,9,6,10},其中a[10] = {3,5,7,1,9,2,4,8,6,10}是一个合法的输出。分析:方法一:遍历一遍数组,vector1存奇数,vector2存偶数,然后vector2加到vector1后面。方法二:快排的思想,首尾两个指针,向前向后遍历,交换奇偶数原创 2017-08-20 22:28:22 · 604 阅读 · 0 评论 -
递归实现牛顿法求整数平方根
原理: 给一个初始值(比如X1 = a/2)迭代求a的平方根,设定一个误差限,不断逼近a X1 = a/2 X2 = (X1+a/X1)/2 … … … Xn+1 = (Xn+a/Xn)/2方法: 递归代码:#include "stdafx.h"double getRoot(double x2,double n原创 2017-08-25 19:03:09 · 3522 阅读 · 0 评论 -
每天一道算法题——Leecode.386. Lexicographical Numbers
题目:Given an integer n, return 1 - n in lexicographical order.For example, given 13, return: [1,10,11,12,13,2,3,4,5,6,7,8,9].Please optimize your algorithm to use less time and space. The input原创 2017-08-22 17:27:27 · 312 阅读 · 0 评论 -
每天一道算法题——LeeCode.387. First Unique Character in a String
题目:Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1.Examples:s = "leetcode"return 0.s = "loveleetcode",return 2.Note: Y原创 2017-08-22 18:23:11 · 349 阅读 · 0 评论 -
每天一道算法题——LeeCode.389. Find the Difference
题目:Given two strings s and t which consist of only lowercase letters.String t is generated by random shuffling string s and then add one more letter at a random position.Find the letter that原创 2017-08-24 09:17:09 · 317 阅读 · 0 评论 -
旋转矩阵
给定一个n×n的二维矩阵表示一个图像。将图像顺时针旋转 90 度。给定 matrix = [ [1,2,3], [4,5,6], [7,8,9]],原地旋转输入矩阵,使其变为:[ [7,4,1], [8,5,2], [9,6,3]]void rotate(vector<vector<int>>& mat...原创 2019-05-28 18:45:43 · 512 阅读 · 0 评论