Python
文章平均质量分 61
繁华落尽梦一场-
这个作者很懒,什么都没留下…
展开
-
[LeetCode] Majority Element
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element原创 2015-04-29 17:11:46 · 349 阅读 · 0 评论 -
python调用dll 出现[Error 193]
装了好几个版本的python,搞乱了,卸载后重装了,但跑之前的代码时出了WindowsError: [Error 193] %1 不是有效的 Win32。这其实因为python位数和dll位数不一样导致的,dll是32位的,而python是64位的,所以不行。解决办法之一是将dll编译成64位的,另一办法是装个32位的python。原创 2015-05-27 11:50:45 · 9107 阅读 · 0 评论 -
Python:Tkinter之Radiobutton
最近才刚开始学pythonGUI,虽然用Python做GUI肯定不是明智之举,但为了学习,还是了解了解,今天先来看看 Radiobutton,没什么可说的,直接贴代码。from Tkinter import * def sel(): selection = "You selected the option " + str(var.get()) label.c原创 2015-05-15 18:38:27 · 9296 阅读 · 0 评论 -
Python调用DLL
C语言中的函数默认是__cdecl调用,C++中可用__stdcall来显示声明调用,但也可以用extern “C”用python调用dll时需要根据不同的调用约定而使用不同的函数。但是不管什么调用,最后都必须用extern “C”来防止名字粉碎。dll源文件:#include extern "C" _declspec(dllexport) int __stdcall stdAd原创 2015-05-04 22:27:21 · 937 阅读 · 0 评论 -
Python线程间的同步与互斥
最简单来说,假如有3个线程同时访问一个全局变量,那么很可能会操作互斥错误的情况,代码如下:#!/usr/bin/python#encoding=utf-8import timeimport threadingindex = 0def printIndex(): global index global lock while index < 100:原创 2015-05-05 15:42:55 · 612 阅读 · 0 评论 -
[LeetCode] Find Minimum in Rotated Sorted Array
Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).Find the minimum element.You may assume no duplicate exists in the ar原创 2015-05-04 12:21:29 · 443 阅读 · 0 评论 -
[LeetCode] Two Sum
Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target, whe原创 2015-05-04 10:09:38 · 391 阅读 · 0 评论 -
Python 一步一步学网络编程
就像当初用C++写网络程序一样,Python的第一个网络程序肯定是最简单的阻塞的那种,即服务器绑定监听,等待客户端的连接,如果有客户端连接,则建立连接进行通信,服务器是阻塞的没有多线程。服务端:#/usr/bin/python#encoding=utf-8import socketsock = socket.socket(socket.AF_INET, socket.SOCK_原创 2015-04-28 17:26:34 · 505 阅读 · 0 评论 -
[LeetCode] Binary Tree Level Order Traversal
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree {3,9,20,#,#,15,7}, 3 / \ 9 20原创 2015-04-28 14:49:20 · 431 阅读 · 0 评论 -
[LeetCode] Symmetric Tree 判断二叉树是否为对称二叉树
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3But the f原创 2015-04-28 10:10:25 · 601 阅读 · 0 评论 -
总结:和链表有关面试题
面试中被问链表的题目我就不再多说,直接总结题目。1、将链表逆序这个问题很早就研究过,但后来一次面试的时候我突然紧张忘了,没答上来。我不知道大家的解法是什么,我的解法是遍历链表是用前插发插入节点,最后的链表就是逆序的。class ListNode: def __init__(self, x): self.val = x self.next =原创 2015-04-30 15:19:27 · 435 阅读 · 0 评论 -
[LeetCode] Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.题目大概意思是说求二叉树的最小深度,原创 2015-04-27 17:48:39 · 357 阅读 · 0 评论 -
[LeetCode] Path Sum 求二叉树中满足要求的路径
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary tree and sum原创 2015-04-27 17:24:32 · 585 阅读 · 0 评论 -
[LeetCode] 判断两个链表是否有公共节点并返回第一个公共节点
Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a1 → a2 ↘原创 2015-04-27 15:02:01 · 2048 阅读 · 0 评论 -
python字符串操作
不管什么语言,在很多情况下我们都是在操作字符串,所以掌握字符操作就掌握了这门语言大半。一、去空格python中有个strip函数,作用是去掉字符串中的某一个字符,类似的还有lstrip和rstrip表示去掉左面和右面某一字符,它们的默认参数是空格。1、strip()用来在字符串的首尾删除某个字符。s = 'abcd'.strip('a') #s = 'bcd',删除了首部原创 2015-06-24 15:48:41 · 532 阅读 · 0 评论