python leetcode相关题目
来源:互联网 发布:java api1.6文档下载 编辑:程序博客网 时间:2024/05/17 23:31
Reshape the Matrix
class Solution(object): def matrixReshape(self, nums, r, c): """ :type nums: List[List[int]] :type r: int :type c: int :rtype: List[List[int]] """ l = [] for i in nums: for j in range(len(i)): l.append(i[j]) if len(l) != r*c: return nums else: x = [] y = int(len(l)/c) for i in range(y): x.append(l[i*c:(i*c+c)]) return xif __name__ == '__main__': a = [[2,3,4],[1,3]] a = Solution() print(a.matrixReshape([[1,2],[3,4]],1,4))
Hamming Distance
class Solution(object): def hammingDistance(self, x, y): """ :type x: int :type y: int :rtype: int """ # def get_list(a): # a_list = list(bin(a))[2:] # return a_list # a_str = ''.join(a_list) x1 = list(bin(x))[2:] y1 = list(bin(y))[2:] if len(x1)>len(y1): x_ins = len(x1)-len(y1) for i in range(x_ins): y1.insert(0,'0') else: y_ins = len(y1)-len(x1) for i in range(y_ins): x1.insert(0,'0') print(x1) print(y1) i = 0 for n in range(len(x1)): if x1[n] == y1[n]: i += 1 count = len(x1)-i return countif __name__ == '__main__': a = Solution() print(a.hammingDistance(34,4))
阅读全文
0 0
- python leetcode相关题目
- python爬虫抓取LeetCode题目
- Leetcode两道小题目python试水
- 【LeetCode】题目难度以及相关算法
- [Leetcode][链表]相关题目汇总/分析/总结
- LeetCode: Binary Tree Depth相关题目合集
- LeetCode:Binary Search Tree相关题目合集
- LeetCode: Binary Tree Sum相关题目合集
- [Leetcode]database 相关题目的总结
- 几个字符串相关的题目,来自LeetCode和LintCode
- zigzag相关题目2--LeetCode(6) ZigZag Conversion
- 【二叉树】常用处理与leetcode相关题目总结
- [Leetcode][二叉树]相关题目汇总/分析/总结
- [LeetCode]Sliding Window Algorithm相关题目总结【重要】
- 算法思想-深度搜索算法-leetcode相关题目总结
- [Leetcode][双指针/多指针]相关题目汇总/分析/总结
- leetcode题目
- LeetCode 题目
- ActiveMQ5.14.3持久化信息到MySQL的一些注意事项
- 强化学习笔记01,02——强化学习问题和Multi-arm Bandits
- 用opensmile批量提取语音特征
- hadoop-hdfs-架构
- Linux下的共享内存
- python leetcode相关题目
- OpenGL 矩阵 行序 列序
- (三)UI绘制流程-流式布局
- 2011蓝桥杯 最小公倍数 NOYJ517
- Java定时任务调度工具-Timer
- 实现手机左右滑屏效果
- 2017暑期实习面经分享(大数据&Java&后台)
- c++---回文数
- Tornado——一个异步web服务器