python 判断矩阵中每行非零个数的方法: # -*- coding: utf-8 -*- # @Time : 2018/5/17 15:05 # @Author : Sizer # @Site : # @File : test.py # @Software: PyCharm import time import numpy as np # data = np.array([ # [5.0, 3.0, 4.0, 4.0, 0.0], # [3.0, 1.0, 2.0, 3.0, 3.0], #…
python 判断字符串中是否只有中文字符 学习了:https://segmentfault.com/q/1010000007898150 def is_all_zh(s): for c in s: if not ('\u4e00' <= c <= '\u9fa5'): return False return True…
python判断字符串中是否包含子字符串 s = '1234问沃尔沃434' if s.find('沃尔沃') != -1:     print('存在') else:     print('不存在')…
python判断list中是否包含某个元素 theList = ['a','b','c'] if 'a' in theList: print 'a in the list' if 'd' not in theList: print 'd is not in the list'…
401-排序矩阵中的从小到大第k个数 在一个排序矩阵中找从小到大的第 k 个整数. 排序矩阵的定义为:每一行递增,每一列也递增. 样例 给出 k = 4 和一个排序矩阵: [ [1 ,5 ,7], [3 ,7 ,8], [4 ,8 ,9], ] 返回 5. 挑战 使用O(k log n)的方法,n为矩阵的宽度和高度中的最大值. 标签 堆 优先队列 矩阵 思路 利用类似于小顶堆的方法,将排序矩阵 matrix 化为小顶堆,即 matrix[0][0] 为矩阵中最小元素,且矩阵每一行递增,每一列也递…
Java:判断字符串中包含某字符的个数 JAVA中查询一个词在内容中出现的次数: public int getCount(String str,String key){ if(str == null || key == null || "".equals(str.trim()) || "".equals(key.trim())){ return 0; } int count = 0; int index = 0; while((index=str.indexOf(k…
/** * 判断字符串中某个字符存在的个数 * @param str1 完整字符串 * @param str2 要统计匹配个数的字符 * @return */ public static int countStr(String str1, String str2) { int count=0; if (str1.indexOf(str2) == -1) { return 0; } while(str1.indexOf(str2)!=-1){ count++; str1=str1.substrin…
[字符串与数组] Q:Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column is set to 0. 题目:写一个算法,如果一个 MxN矩阵中某个元素为0,则将该元素所在的行.列都置为0. 解答: 方法一:错误的解法,思维误区.依次遍历二维数组(矩阵),遇到一个0,就将这个0所在的行和列全部置为0,咋看一下没问题,仔细一想不对啊,这样做后,很有可能操作完后,这个二维数…
[抄题]: 在一个排序矩阵中找从小到大的第 k 个整数. 排序矩阵的定义为:每一行递增,每一列也递增. [思维问题]: 不知道应该怎么加,因为不是一维单调的. [一句话思路]: 周围两个数给x或y挪一位, 如果hash数组没有就添加到minheap中 [输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入): [画图]: [一刷]: class Pair(没有参数)中要有数据类型.方法Pair(int x , int y, int val) PairComp…
代码适用情况:xml文件,循环出现某几行,根据这几行中的某个字段删掉这几行这段代码的作用删除jenkins中config.xml中在自动生成pipline报错的时的回滚 start = '<se.diabol.jenkins.pipeline.DeliveryPipelineView plugin=' end = '</se.diabol.jenkins.pipeline.DeliveryPipelineView>' def delete_pip(src): f = open(src,…