摘要: 正常解法 以上是正常解法,但认真分析可以发现其复杂度是O(n^2),原因很简单,首先先逐个查找去掉某一个字符的字符串是不是回文序列,查找需要n次,同时字符串与reverse后字符串的比较的次数也为n次,由此可见算法复杂度是n^2,这在leetcode上运行时会出现严重的超时,故采取第二种简单的做法, 阅读全文
posted @ 2017-10-29 13:38 PirateLHX 阅读(189) 评论(4) 推荐(0)
摘要: class Solution { public: //int compare(const void * arg1, const void *arg2) //{ //return (*(int*)arg1 - *(int*)arg2); //} vector twoSum(vector& nums, int target) { vector res; vector... 阅读全文
posted @ 2017-09-23 23:37 PirateLHX 阅读(95) 评论(0) 推荐(0)
摘要: 题目:给出一个数组,将其分为两份,使得这两份差值最小。 解答: 比如a={4,3,2,1},其实只要让其逼近sum(a)/2即可,所以可以等效于一个背包容量为5,从a中取出若干件物品,将其装满,但是这样会出现问题,就是4+1,3+1都符合条件,(如果我们假设他们价值为1的话,受网上误导很大),事实上 阅读全文
posted @ 2017-09-22 12:27 PirateLHX 阅读(301) 评论(0) 推荐(0)
摘要: #include #include #include #include using namespace std; char* res[26]; struct Node { Node* left; Node* right; char num; Node() { }; Node(char c, Node* l = N... 阅读全文
posted @ 2017-09-21 23:36 PirateLHX 阅读(133) 评论(0) 推荐(0)
摘要: 典型DFS问题 注意每次新的寻迹都要重新初始化 DFS路径不成功要将路径的标记去掉 记得return,递归 #include<iostream> #include<memory.h> using namespace std; int result[30]; int a[5][6]; int flag 阅读全文
posted @ 2017-09-20 16:34 PirateLHX 阅读(234) 评论(0) 推荐(0)
摘要: 思路:深度搜索每个城市是否存在道路,并用一个数组保存访问记录,识别能不能到达终点。 阅读全文
posted @ 2017-09-19 22:55 PirateLHX 阅读(192) 评论(0) 推荐(0)
摘要: #include #include #include #include #include using namespace std; int cmp(int a,int b){ return a>len; cin>>number; int* a=new int[number]; for(int i=0;i>DNA; dnalist[i].dna=DNA; measur... 阅读全文
posted @ 2017-09-13 20:21 PirateLHX 阅读(110) 评论(0) 推荐(0)
摘要: http://blog.csdn.net/mhxy199288/article/details/37766679 阅读全文
posted @ 2017-09-04 11:42 PirateLHX 阅读(592) 评论(0) 推荐(0)
摘要: 有两个数组a,b,大小都为n,数组元素的值任意,无序;通过交换a,b中的元素,使数组a元素的和与数组b元素的和之间的差最小。 C++:http://blog.csdn.net/cwqbuptcwqbupt/article/details/7521733 python:http://www.iteye 阅读全文
posted @ 2017-09-04 11:24 PirateLHX 阅读(135) 评论(0) 推荐(0)
摘要: import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data import numpy as np from skimage.io import imsave import os import shutil img_height = 28 img_width = 28 img_size = ... 阅读全文
posted @ 2017-09-01 16:58 PirateLHX 阅读(322) 评论(0) 推荐(0)