![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
手写算法
手写算法
ailinyingai
DevOps 搬砖人 干饭人
展开
-
dfs
def recursive_dfs(graph, start, path=None): if path is None: path = [] path.append(start) for node in graph[start]: if not node in path: recursive_dfs(graph, no...原创 2020-02-29 10:58:12 · 216 阅读 · 0 评论 -
0218文档
https://blog.csdn.net/qq_39397165/article/details/104365271https://blog.csdn.net/FBB360JAVA/article/details/104359423?request_id=&utm_source=distribute.pc_feed.none-task原创 2020-02-18 16:37:23 · 117 阅读 · 0 评论 -
最小数
输入一个正整数数组,把数组里所有数字拼接起来排成一个数,打印能拼接出的所有数字中最小的一个。例如输入数组{3,32,321},则打印出这三个数字能排成的最小数字为321323。/** * 把数组排成最小的数 * 解决办法: 我们把两个数字相加 正向 和 反向 来比较,然后做替换。 */public class Solution { public String PrintMinNu...原创 2020-02-18 15:20:09 · 507 阅读 · 0 评论 -
连续子数组最大和
/** * 连续子数组的最大和 * 思路:最大子数组的和一定是由当前元素和之前最大连续子数组的和叠加在一起形成的 */public class Solution { public int FindGreatestSumOfSubArray(int[] array) { if(array.length==0||array==null) { ...原创 2020-02-18 15:10:49 · 117 阅读 · 0 评论 -
knn手写识别
# coding=utf-8import matplotlibmatplotlib.use('Qt4Agg')# 手写数字分类from sklearn.model_selection import train_test_splitfrom sklearn import preprocessingfrom sklearn.metrics import accuracy_scorefr...原创 2020-02-05 11:36:55 · 288 阅读 · 1 评论 -
马踏棋盘
# 马踏棋盘算法class HorseChessBoard(object): def __init__(self, size): self.X = size # 棋盘的列数 self.Y = size # 棋盘的行数 # 创建一个二维数组,用于记录每一步所走的位置 self.chess_board = [[0 for ...原创 2020-02-03 10:17:30 · 146 阅读 · 0 评论 -
找零二维
找零二维import sysmax = sys.maxsizedef giveChange(coinList,totalCoin): result = [[0 for i in range(totalCoin + 1)] for j in range(len(coinList) + 1)] for j in range(totalCoin+1): re...原创 2020-01-21 09:24:17 · 121 阅读 · 0 评论 -
扔鸡蛋
class Solution: def superEggDrop(self, K, N): dp = [[0 for _ in range(N + 1)] for _ in range(K + 1)] for i in range(1, K + 1): for step in range(1, N + 1): ...原创 2020-01-18 16:02:16 · 125 阅读 · 0 评论 -
货币找零
class Solution(object): def coinChange(self, coins, amount): """ :type coins: List[int] :type amount: int :rtype: int """ n = len(coins) # d...原创 2020-01-18 15:45:43 · 505 阅读 · 0 评论 -
超级洗衣机
class Solution: def findMinMoves(self, machines: List[int]) -> int: sum_ = sum(machines) l = len(machines) if sum_ % l != 0: return -1 target = int(s...原创 2020-01-18 15:38:18 · 154 阅读 · 0 评论 -
BM
def string_match_boyer_moore(string,match,start=0): string_len = len(string) match_len = len(match) end = match_len - 1 print (string) print (match) print ('******') if st...原创 2020-01-18 11:38:21 · 159 阅读 · 0 评论 -
KMP
def prefixTable(pattern): m = len(pattern) F = [0] * m k = 0 for q in range(1, m): while k > 0 and pattern[k] != pattern[q]: k = F[k - 1] if pattern[k] =...原创 2020-01-18 11:14:55 · 127 阅读 · 0 评论 -
RK字符串匹配
def RobinKarp(text, pattern): if pattern == None or text == None: return -1 if pattern == "" or text == "": return -1 if len(pattern) > len(text): return -1 ...原创 2020-01-18 10:55:56 · 200 阅读 · 0 评论 -
fib
https://www.jianshu.com/p/f0513d18742a0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, …Matrix2By2...原创 2020-01-16 14:02:14 · 214 阅读 · 0 评论 -
路径和四
【题目描述】如果树的深度小于5,则该树可以由三位整数的列表表示。对于此列表中的每个整数:百位数表示该节点的深度D,1 <= D <= 4。2.十位数表示该节点在其所属级别中的位置P,1 <= P <= 8.该位置与完整二叉树中的位置相同。3.单位数字表示该节点的值V,0 <= V <= 9。给定一个表示深度小于5的二叉树的升序三位整数列表,您需要返回...原创 2020-01-16 11:42:40 · 202 阅读 · 0 评论 -
平方根
class Solution: def mySqrt(self, x): if x < 0: raise Exception('不能输入负数') if x == 0: return 0 # 起始的时候在 1 ,这可以比较随意设置 cur = 1 while...原创 2020-01-14 17:04:02 · 199 阅读 · 0 评论 -
旋转矩阵
class Solution: def rotate(self, matrix): """ :type matrix: List[List[int]] :rtype: void Do not return anything, modify matrix in-place instead. """ m = len...原创 2020-01-14 16:27:16 · 129 阅读 · 0 评论 -
最长上升子序列
class Solution: """ @param nums: An integer array @return: The length of LIS (longest increasing subsequence) """ def longestIncreasingSubsequence(self, nums): # write your...翻译 2020-01-14 16:17:59 · 60 阅读 · 0 评论 -
字母异位词 java
public boolean isAnagram(String s, String t) { if (s.length() !=t.length()) return false int[] table = new int[62] for (int i=0;i<s.length();i++){ table[s.charAt(i)-'a']++; } for (int i=0...原创 2020-01-11 09:29:47 · 392 阅读 · 0 评论 -
最长公共子串
def find_lcsubstr(s1, s2): m=[[0 for i in range(len(s2)+1)] for j in range(len(s1)+1)] #生成0矩阵,为方便后续计算,比字符串长度多了一列 mmax=0 #最长匹配的长度 p=0 #最长匹配对应在s1中的最后一位 for i in range(len(s1)): for j in rang...原创 2020-01-10 15:36:46 · 148 阅读 · 0 评论 -
KMP
void GetNext(char* pattern,int next[]) { int k = -1; int j = 0; int length_pattern = strlen(pattern); next[0] = -1; while (j < length_pattern - 1) { //p[k]表示前缀,p[j]表示后缀 if (k...原创 2020-01-10 14:40:01 · 88 阅读 · 0 评论 -
称砝码
//称砝码int main() { int n; cin >> n; int max_wight = 0; vector<int> nums(n), wights(n); for (int i = 0; i < n; i++) cin >> wights[i]; for (int i = 0; i < n; i++) { ci...原创 2020-01-10 13:33:56 · 198 阅读 · 0 评论 -
排序汇总
# -*- coding=utf8 -*-def bubble(alist): """冒泡排序O(n^2)""" n = len(alist) for j in range(n-1, 0, -1): for i in range(j): if alist[i] > alist[i+1]: a...原创 2019-12-28 10:39:58 · 80 阅读 · 0 评论 -
快排 同向双指针对向双指针
#include<stdio.h>#include<iostream> //算法导论中第七章原文中给出的方式,同侧的两个指针void QuickSort1(int* data,int num,int r){ int val=data[r-1]; int* pFirst=data; int* pSec=data; while(pFirst<=da...原创 2019-12-28 10:37:36 · 198 阅读 · 0 评论 -
0054
#include <stdio.h>#include <iostream>/*-------------------数组中的奇偶数分开排列-------------------*/void OddEvenClassify(int* data,int num){ int* pBegin=data; int* pEnd=data+num-1; while(pBeg...原创 2019-12-28 10:03:36 · 116 阅读 · 0 评论 -
0063
#include <stdio.h>#include <iostream>#include <map>using std::map;/*-----------构建被删除字符串的哈希表---------------*///为了快速确定当前字符是否属于可删除字符,可通过构建//可删除字符的哈希表 //此处利用了STL中的关联容器,map map&...原创 2019-12-28 09:56:21 · 99 阅读 · 0 评论 -
devops
基于PaaS开发模式催生的运维开发岗位,与普通的业务开发不同,与日常的运维工作也不同。要求兼顾开发与运维两种能力。既要掌握不弱于业务开发的开发技术;又要负责SRE同学日常的运维能力;上线之前,还要像QA同学一样,对自己的服务进行测试和分级变更。import mathclass Solution: def climbStairs(self, n: int) -> int: ...原创 2019-12-23 15:31:23 · 72 阅读 · 0 评论 -
parking_lot
from abc import ABCMeta, abstractmethodfrom enum import Enumclass VehicleSize(Enum): MOTORCYCLE = 0 COMPACT = 1 LARGE = 2class Vehicle(metaclass=ABCMeta): def __init__(self, v...原创 2019-12-07 23:14:36 · 304 阅读 · 0 评论 -
lru-cache
class Node(object): def __init__(self, results): self.results = results self.next = nextclass LinkedList(object): def __init__(self): self.head = None self...原创 2019-12-06 11:39:31 · 204 阅读 · 0 评论 -
预测股票的变化--卡尔曼滤波
import tensorflow as tfimport numpy as npclass KalmanFilter(object): def __init__(self, x=None, A=None, P=None, B=None, H=None, Q=None): m = self._m = H.shape[0] n = self._n = ...原创 2019-12-06 11:05:36 · 2070 阅读 · 0 评论 -
去掉一个数 让剩余的数乘积最大
#!/usr/bin/env python# coding=utf-8def solve(arr): ans = [i for i in arr if i < 0] ant = [i for i in arr if i >= 0] if not ans: return sorted(arr)[0] length = len(ans)...原创 2019-12-06 10:23:20 · 221 阅读 · 0 评论 -
字典树
#coding=utf-8class Trie: root = {} END = '/' def add(self, word): #从根节点遍历单词,char by char,如果不存在则新增,最后加上一个单词结束标志 node = self.root for c in word: node=nod...原创 2019-12-04 17:50:24 · 60 阅读 · 0 评论 -
最长有效括号
public int longestValidParentheses(String s) { if(s == null || s.length() < 1) return 0; int left = 0, right = 0, max = 0; // 从左到右 for (int i = 0; i < s.length(); i++) { i...原创 2019-11-29 16:24:30 · 80 阅读 · 0 评论 -
the most wanted letter
from string import ascii_lowercase as letterscheckio = lambda text: max(letters, key=text.lower().count)原创 2019-11-27 14:56:29 · 94 阅读 · 0 评论 -
层次遍历
# 思路来自:https://leetcode-cn.com/problems/binary-tree-level-order-traversal/solution/er-cha-shu-de-ceng-ci-bian-li-by-leetcode/from collections import deque# 层次遍历非递归实现def hierarchical_traversal(roo...原创 2019-11-25 14:48:08 · 270 阅读 · 2 评论 -
旋转数组
class Solution {public: int minNumberInRotateArray(vector<int> rotateArray) { if (rotateArray.size()==0) { return 0; } int low=0, high=rotateArray.size()...原创 2019-11-21 10:52:05 · 82 阅读 · 0 评论 -
位运算实现加减乘除
#include <iostream>#include <climits>#include <random>using namespace std;class Solution {public: int add(int a, int b) { return b == 0 ? a : add(a ^ b, (a &a...原创 2019-11-20 14:09:53 · 106 阅读 · 0 评论 -
one_way
import unittestdef one_away(s1, s2): '''Check if a string can converted to another string with a single edit''' if len(s1) == len(s2): return one_edit_replace(s1, s2) elif len(s...原创 2019-11-14 16:04:57 · 109 阅读 · 0 评论 -
pal_permu
import unittestdef pal_perm(phrase): '''function checks if a string is a permutation of a palindrome or not''' table = [0 for _ in range(ord('z') - ord('a') + 1)] countodd = 0 for c...原创 2019-11-14 15:57:55 · 60 阅读 · 0 评论 -
check permu
import unittestfrom collections import Counterdef check_permutation(str1, str2): if len(str1) != len(str2): return False counter = Counter() for c in str1: counter[c] +...原创 2019-11-13 09:26:29 · 95 阅读 · 0 评论