- 博客(36)
- 收藏
- 关注
转载 Windows 命令行下解决python utf-8中文输出的终极解决方案!
代码参考了这里:http://wiki.python.org/moin/PrintFails上文对各种系统无法输出奇葩编码的字符做了总结,本文中只针对windows cmd下GBK编码(cp936)但想执行utf-8编码的python文件进行修改。原理就是:Another is to put an intercept between sys.stdout, an
2016-01-24 20:34:03 5591 2
转载 Leetcode243: Find Median from Data Stream
Median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle value.Examples: [2,3,4] , the median
2016-01-24 16:27:18 459
转载 Leetcode242: Shortest Palindrome
Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest palindrome you can find by performing this transformation.For exam
2016-01-24 14:15:13 391
转载 Leetcode241: Valid Number
Validate if a given string is numeric.Some examples:"0" => true" 0.1 " => true"abc" => false"1 a" => false"2e10" => trueNote: It is intended for the problem statement to be ambiguo
2016-01-22 21:13:39 500
转载 Leetcode240: Word Break II
Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word.Return all such possible sentences.For example, givens = "
2016-01-15 21:26:56 403
原创 Leetcode239: Dungeon Game
The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a 2D grid. Our valiant knight (K) was initially p
2016-01-15 20:58:49 346
转载 Leetcode238: Substring with Concatenation of All Words
You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in wordsexactly once and w
2016-01-15 10:42:17 335
转载 Leetcode237: Palindrome Partitioning II
Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning of s.For example, given s = "aab",Retu
2016-01-15 09:39:46 426
转载 Leetcode236: Interleaving String
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example,Given:s1 = "aabcc",s2 = "dbbca",When s3 = "aadbbcbcac", return true.When s3 = "aadbbbaccc", r
2016-01-14 21:49:18 357
转载 Leetcode235: Longest Valid Parentheses
Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the longest valid parentheses substring is "()",
2016-01-14 21:14:48 345
转载 Leetcode234: Recover Binary Search Tree
Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is pretty straight forward. Could you devis
2016-01-14 20:58:03 431
转载 Leetcode233: Scramble String
Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation of s1 = "great": great / \ gr
2016-01-14 17:37:13 411
转载 Leetcode232: Copy List with Random Pointer
A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list.网上看到一个O(n)的算法,非常巧妙的利用了原来链表
2016-01-14 17:11:44 406
转载 Leetcode231: Minimum Window Substring
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S = "ADOBECODEBANC"T = "ABC"Minimum window is "BAN
2016-01-13 22:27:47 346
原创 Leetcode230: Power of Three
Given an integer, write a function to determine if it is a power of three.Follow up:Could you do it without using any loop / recursion?解法一:class Solution {public: bool isPowerOfThree(
2016-01-13 21:54:25 469
原创 Leetcode229: Max Points on a Line
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.以每个点为源点,计算所有点与该点的斜率,用哈希表存储同一斜率的点数,找出对于这个点最大共线的点数,再找出所有点中最大的点数即可。/** * Definition for a point.
2016-01-13 21:30:06 388
转载 Leetcode228: Regular Expression Matching
Implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the entire input st
2016-01-13 11:29:04 373
转载 Leetcode227: Best Time to Buy and Sell Stock IV
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 at most k transactions.Note:You may
2016-01-12 22:30:01 335
原创 Leetcode226: Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.可以借鉴Merge two sorted lists的方法,在他的基础上用分治算法。/** * Definition for singly-linked list. * struct Li
2016-01-12 22:08:04 277
转载 Leetcode225: Candy
There are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must have at least on
2016-01-08 20:56:55 426
转载 Leetcode224: Sudoku Solver
Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character '.'.You may assume that there will be only one unique solution.A sudoku
2016-01-08 20:38:18 310
转载 OpenCV函数cvFindContours轮廓提取
提取轮廓在OpenCV里有一个函数 cvFindContours :[cpp] view plaincopyint cvFindContours( CvArr* image, CvMemStorage* storage, CvSeq** first_contour,int header_size=sizeof(CvContour),int mode=CV_RETR_LIST,int method=
2016-01-08 15:18:45 2948
原创 Leetcode223: Insert Interval
Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their start times.E
2016-01-08 11:20:29 363
转载 Leetcode222: Jump Game II
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Your goal i
2016-01-08 10:25:47 412
转载 Leetcode221: Sliding Window Maximum
Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window
2016-01-08 09:46:31 388
原创 Leetcode220: First Missing Positive
Given an unsorted integer array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm should run in O(n) time and uses constant
2016-01-07 16:44:35 301
转载 Leetcode219: Merge Intervals
Given a collection of intervals, merge all overlapping intervals.For example,Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,18]./** * Definition for an interval. * struct Interva
2016-01-07 15:48:20 272
原创 Leetcode218: Maximum Gap
Given an unsorted array, find the maximum difference between the successive elements in its sorted form.Try to solve it in linear time/space.Return 0 if the array contains less than 2 elements
2016-01-07 15:22:35 444
转载 Leetcode217: Reverse Nodes in k-Group
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is
2016-01-07 14:58:54 286
转载 Leetcode216: Edit Distance
Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:
2016-01-07 11:11:28 284
转载 Leetcode215: Distinct Subsequences
Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleting some (can be non
2016-01-05 14:08:18 251
转载 Leetcode214: Remove Invalid Parentheses
Remove the minimum number of invalid parentheses in order to make the input string valid. Return all possible results.Note: The input string may contain letters other than the parentheses ( and ).
2016-01-04 21:07:31 268
转载 Leetcode213: Longest Consecutive Sequence
Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given [100, 4, 200, 1, 3, 2],The longest consecutive elements sequence is [1, 2, 3
2016-01-04 17:15:44 318
转载 Leetcode212: Burst Balloons
Given n balloons, indexed from 0 to n-1. Each balloon is painted with a number on it represented by array nums. You are asked to burst all the balloons. If the you burst balloon i you will get num
2016-01-04 15:58:02 389
转载 Leetcode211: Populating Next Right Pointers in Each Node II
Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution still work?Note:You may only use constant
2016-01-04 11:29:48 288
原创 Leetcode210: 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 pivot unk
2016-01-03 19:56:50 308
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人