- 博客(71)
- 资源 (4)
- 收藏
- 关注
原创 win7 python安装PIL
今天在win7 64位电脑安装PIL时,出现一些问题,为方便以后查看,再次记录。 PIL地址: 64位电脑:PIL下载地址:https://pypi.python.org/pypi/Pillow/2.1.0#id2下载Pillow-2.1.0.win-amd64-py2.7.exe (md5) 32位电脑:PIL下载地址:https://pypi.py
2016-11-11 13:36:45 967
原创 Move Zeroes
题目描述:Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.For example, given nums = [0, 1, 0, 3, 12], after calling
2015-09-20 20:44:12 494
原创 Search Insert Position
题目描述:Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the a
2015-09-11 16:36:42 381
原创 Intersection of Two Linked Lists
题目描述: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-09-11 16:34:02 324
原创 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.解
2015-09-11 16:29:22 335
原创 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 dayi.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie
2015-09-09 21:59:42 474
原创 Best Time to Buy and Sell Stock
题目描述:Say you have an array for which the ith element is the price of a given stock on dayi.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the
2015-09-09 21:56:06 547
原创 Remove Linked List Elements
题目描述:Remove all elements from a linked list of integers that have value val.ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2 --> 3 --> 4 --> 5 解题思路:由于存在重复值
2015-09-09 21:51:23 260
原创 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? 解题思路:由于不使用额外的空间,所以可以在扫描节点之后,让节点后继指针指向头节点,如果以后扫描的后继节点与头节点相同,有环。Java实现:/**
2015-09-09 21:46:39 339
原创 Binary Tree Inorder Traversal
题目描述:Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,3,2]. Note: Recursive sol
2015-09-09 08:07:43 405
原创 Binary Search Tree Iterator
题目描述:Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Calling next() will return the next smallest number in the BST.Note: n
2015-09-09 08:04:37 533
原创 Kth Largest Element in an Array
题目描述:Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.For example,Given [3,2,1,5,6,4] and k = 2,
2015-09-09 08:00:43 439
原创 First Bad Version
题目描述:You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed b
2015-09-09 07:57:06 493
原创 Find Minimum in Rotated Sorted Array II
题目描述:Follow up for "Find Minimum in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Suppose a sorted array is rotated at some pivo
2015-09-09 07:54:02 386
原创 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
2015-09-09 07:49:46 333
原创 Contains Duplicate
题目描述:Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every
2015-09-09 07:40:07 373
原创 Reverse Linked List
题目描述:Reverse a singly linked list.解题思路:从头指针开始依次改变next指针指向,注意保存后续节点指针。Java代码实现:/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * Li
2015-09-09 07:39:30 335
原创 Binary Tree Postorder Traversal
题目描述:Given a binary tree, return the postorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [3,2,1]. Note: Recursive s
2015-09-08 12:59:05 325
Binary Tree Postorder Traversal
题目描述:Given a binary tree, return the postorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [3,2,1]. Note: Recursive sol...
2015-09-08 12:59:00 112
原创 Binary Tree Preorder Traversal
Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,2,3]. Note: Recursive solutio
2015-09-08 12:55:00 334
Binary Tree Preorder Traversal
Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,2,3]. Note: Recursive solution ...
2015-09-08 12:55:00 110
原创 Basic Calculator
题目描述:Implement a basic calculator to evaluate a simple expression string.The expression string may contain open ( and closing parentheses ), the plus + or minus sign -, non-negative integers a
2015-09-08 12:50:21 346
Basic Calculator
题目描述:Implement a basic calculator to evaluate a simple expression string.The expression string may contain open ( and closing parentheses ), the plus + or minus sign -, non-negative integers a...
2015-09-08 12:50:00 233
原创 Implement Stack using Queues
题目描述:Implement the following operations of a stack using queues.push(x) -- Push element x onto stack. pop() -- Removes the element on top of the stack. top() -- Get the top element. empty() --
2015-09-08 12:42:59 296
Implement Stack using Queues
题目描述:Implement the following operations of a stack using queues.push(x) -- Push element x onto stack. pop() -- Removes the element on top of the stack. top() -- Get the top element. empty() ...
2015-09-08 12:42:00 138
原创 Reverse Bits
解题思路:该题与上题类似,如果是负数首先转化成正数(+ 2147483647+1),再处理,然后变成2进制数(如果是负数最高位是1),翻转2进制数,变成十进制数,翻转后如果最后位是1,在十进制数基础上加上2147483647+1。Java代码实现:public class Solution { // you need treat n as an unsigned val
2015-09-08 11:18:56 376
Reverse Bits
解题思路:该题与上题类似,如果是负数首先转化成正数(+ 2147483647+1),再处理,然后变成2进制数(如果是负数最高位是1),翻转2进制数,变成十进制数,翻转后如果最后位是1,在十进制数基础上加上2147483647+1。Java代码实现:public class Solution { // you need treat n as an unsigned va...
2015-09-08 11:18:00 133
原创 Number of 1 Bits
解题思路:32位有符号整数的表示范围:-2147483648—2147483647。32位无符号整数的表示范围:0—2147483647+2147483648。如果输入的无符号数大于2147483647,则会显示成负数,所以当输入数字小于0时,只需加上2147483647+1,之后按照整数求1的个数,此时需要将1的个数加1.Java代码实现:public class Solution {
2015-09-08 11:16:03 413
Number of 1 Bits
解题思路:32位有符号整数的表示范围:-2147483648—2147483647。32位无符号整数的表示范围:0—2147483647+2147483648。如果输入的无符号数大于2147483647,则会显示成负数,所以当输入数字小于0时,只需加上2147483647+1,之后按照整数求1的个数,此时需要将1的个数加1.Java代码实现:public class Solution...
2015-09-08 11:16:00 103
原创 Invert Binary Tree
解题思路:利用中序遍历的方式,依次交换所遍历节点的左右子树。Java代码实现:/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) {
2015-09-08 11:13:59 406
Invert Binary Tree
解题思路:利用中序遍历的方式,依次交换所遍历节点的左右子树。Java代码实现:/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int ...
2015-09-08 11:13:00 88
原创 Kth Smallest Element in a BST
解题思路:按树的中序遍历的方式,利用栈实现,第k个出栈的节点即是所求的。Java代码实现:/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int
2015-09-08 11:10:42 336
Kth Smallest Element in a BST
解题思路:按树的中序遍历的方式,利用栈实现,第k个出栈的节点即是所求的。Java代码实现:/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(...
2015-09-08 11:10:00 131
原创 Power of Two
解题思路:如果一个数是否是2的次方,即如果其对应的二进制数1的个数如果超过1,不是的2的次方,反之才是。Java代码实现:public class Solution { public boolean isPowerOfTwo(int n) { int count=0; if(n==1) return true; if(n<=0) return
2015-09-08 11:07:49 409
Power of Two
解题思路:如果一个数是否是2的次方,即如果其对应的二进制数1的个数如果超过1,不是的2的次方,反之才是。Java代码实现:public class Solution { public boolean isPowerOfTwo(int n) { int count=0; if(n==1) return true; if(n<=0) r...
2015-09-08 11:07:00 96
原创 Implement Queue using Stacks
解题思路:采用两个栈,实现队列,一个用于进栈S1,一个用于出栈和取头元素S2。进栈时必须将S2中元素全部加入S1中,出栈时必须将S1中的元素加入S2中,才可以保证先进先出。判断为空时,S1,S2均为空。Java代码实现:class MyQueue { private Stack stack1; private Stack stack2; MyQueue(){ stack1=n
2015-09-08 11:05:31 370
Implement Queue using Stacks
解题思路:采用两个栈,实现队列,一个用于进栈S1,一个用于出栈和取头元素S2。进栈时必须将S2中元素全部加入S1中,出栈时必须将S1中的元素加入S2中,才可以保证先进先出。判断为空时,S1,S2均为空。Java代码实现:class MyQueue { private Stack stack1; private Stack stack2; MyQueue(){ stack...
2015-09-08 11:05:00 135
原创 Number of Digit One
解题思路:0-9中1的个数为1个,而X99..9的1的个数可以通过公式计算:即Math.pow(10, digit-1)+(10-(9-highestDigit))*Math.pow(10,digit-2)*(digit-1);比如8999:10^3+9*10^2*3。由此可以将输入数字分解,比如9548=9000+548=9000+500+48=9000+500+40+8,如此分布计算即可
2015-09-08 11:02:00 673
Number of Digit One
解题思路:0-9中1的个数为1个,而X99..9的1的个数可以通过公式计算:即Math.pow(10, digit-1)+(10-(9-highestDigit))*Math.pow(10,digit-2)*(digit-1);比如8999:10^3+9*10^2*3。由此可以将输入数字分解,比如9548=9000+548=9000+500+48=9000+500+40+8,如此分布计算即...
2015-09-08 11:02:00 118
原创 Delete Node in a Linked List
解题思路:指定删除任一节点,因无头节点指针,实际删除节点即是删除节点的值,所以可以将要删除节点和后继节点的值替换,删除后继节点即可。Java代码实现:/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */vo
2015-09-08 10:58:58 486
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人