
LeetCode的Python题解
文章平均质量分 56
本专栏是记录我刷LeetCode的所有心得体会以及全部代码,代码都是用Python书写,格式规范,思路清晰,可读性高。可以为初学Python以及刚刚开始接触LeetCode的新手提供参考。
monkeyduck
清华大学CS在读,研究领域为语音处理、模式识别、对话管理,依然在不断学习中,成功在于点滴积累!
展开
-
【LeetCode】【Python题解】Rotate Image
一行解法以及酷炫解法原创 2014-09-20 15:11:23 · 4804 阅读 · 0 评论 -
【LeetCode】【Python题解】Single NumberII
非常巧妙地解法!原创 2014-09-15 23:08:07 · 2557 阅读 · 0 评论 -
【LeetCode】【Python题解】Pascal's Triangle
仅用一行实现!原创 2014-09-13 23:38:32 · 3448 阅读 · 1 评论 -
【LeetCode】【Python】Sort Colors
Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue. Here, we will use the integers原创 2014-09-11 18:00:03 · 2872 阅读 · 0 评论 -
【LeetCode】Balanced Tree & Binary Search Tree
整合两道差不多的题目放上来,其中第一题是第二题的基础。 1. Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two原创 2014-09-06 20:24:58 · 2787 阅读 · 0 评论 -
【LeetCode】【Python】Binary Tree Inorder Traversal
Given a binary tree, return the inorder traversal of its nodes' values. For example: Given binary tree {1,#,2,3}, 比较简单,就是转化成中序遍历即可,访问顺序是中序遍历左子树,根节点,中序遍历右子树 Python编程的时候需要注意,要在返回单一数字的时候加原创 2014-07-25 09:34:45 · 3548 阅读 · 0 评论 -
【LeetCode】【Python】Linked List Cycle
Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using extra space? 思路:笨办法是每个节点再开辟一个属性存放是否访问过,这样遍历一遍即可知道是否有环。但为了不增加额外的空间,可以设置两个指针,一个一次走一步,另一个一次走两步原创 2014-07-25 09:24:25 · 2130 阅读 · 0 评论 -
【LeetCode】【Python题解】Single Number & Maximum Depth of Binary Tree
今天做了三道LeetCode上的简单题目,每道题都是用c++和Python两种语言写的,因为c++版的代码网上比较多,所以就只分享一下Python的代码吧,刚学完Python的基本语法,做做LeetCode的题目还是不错的,对以后找工作面试也有帮助! 刚开始就从AC率最高的入手吧! 1.Given an array of integers, every element appe原创 2014-07-20 13:18:24 · 4140 阅读 · 0 评论 -
【LeetCode】【Python题解】Same Tree
Given two binary trees, write a function to check if they are equal or not. Two binary trees are considered equal if they are structurally identical and the nodes have the same value. 比较两个原创 2014-07-20 20:01:48 · 3937 阅读 · 0 评论 -
【LeetCode】【Python题解】Reverse Integer
Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 click to show spoilers. Have you thought about this? Here are some good questions to ask before c原创 2014-07-20 20:06:48 · 6789 阅读 · 2 评论 -
【LeetCode】【Python题解】Best Time to Buy and Sell Stock II
Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy on原创 2014-07-24 10:11:44 · 4933 阅读 · 0 评论 -
【LeetCode】【Python题解】Unique Binary Search Trees
Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For example, Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1 \原创 2014-07-24 10:27:20 · 4081 阅读 · 0 评论