[Leetcode] Longest Valid Parentheses @Python - Sumnous's Blog: " if s == '' or s == '(' or s == ')':
return 0
stack = [(-1, ')')]
maxLen = 0
for i in xrange(len(s)):
if s[i] == ')' and stack[-1][1] == '(':
stack.pop()
maxLen = max(maxLen, i - stack[-1][0])
else:
stack.append((i, s[i]))
return maxLen"
'via Blog this'
Blog Archive
-
▼
2014
(190)
-
▼
September
(29)
- [Leetcode] Longest Valid Parentheses @Python - Sum...
- 霸气侧漏的在读博士
- Programming Interview Questions
- temp
- InstallingANewHardDrive - Community Help Wiki
- Clustering With K-Means in Python | The Data Scien...
- LeetCode题解整理版(二) | Coding 4 Fun
- [leetcode]Simplify Path @ Python - 南郭子綦 - 博客园
- [leetcode]Implement strStr() @ Python - 南郭子綦 - 博客园
- [leetcode]Valid Palindrome @ Python - 南郭子綦 - 博客园
- [leetcode]Copy List with Random Pointer @ Python -...
- [leetcode]Swap Nodes in Pairs @ Python - 南郭子綦 - 博客园
- [leetcode]Remove Nth Node From End of List @ Pytho...
- [leetcode]Add Two Numbers @ Python - 南郭子綦 - 博客园
- [leetcode]Rotate List @ Python - 南郭子綦 - 博客园
- [leetcode]Plus One @ Python - 南郭子綦 - 博客园
- [leetcode]Valid Sudoku @ Python - 南郭子綦 - 博客园
- How to Read Linux Top Command Output and Uses - Te...
- [leetcode]Valid Sudoku @ Python - 南郭子綦 - 博客园
- Dropped iphone 5 in water. Help? | Apple Support C...
- [leetcode]Permutation Sequence @ Python - 南郭子綦 - 博客园
- C++11 improvements over C++03
- K-means算法及k-means++、SVD的优化 - 推酷
- Programming Interview Questions
- 统计学习笔记(2)——感知机模型 - Liam Q的专栏 - 博客频道 - CSDN.NET
- 科学网—[转载]常见面试之机器学习算法思想简单梳理 - 李建扣的博文
- soulmachine/machine-learning-cheat-sheet
- 美国一类优先移民EB1A
- c++ - Compiling C++11 with g++
-
▼
September
(29)
Tuesday, September 30, 2014
Monday, September 29, 2014
霸气侧漏的在读博士
George E. Dahl: "George E. Dahl"
Currently, I am not on the job market. However, I expect to finish my Ph.D. this year. If you want to be notified when I start making post-graduation career plans and we haven't already spoken, please send me an email.
http://www.cs.toronto.edu/~gdahl/
[No offense, I just wish I can have the feeling of being a King like this guy]
'via Blog this'
Currently, I am not on the job market. However, I expect to finish my Ph.D. this year. If you want to be notified when I start making post-graduation career plans and we haven't already spoken, please send me an email.
http://www.cs.toronto.edu/~gdahl/
[No offense, I just wish I can have the feeling of being a King like this guy]
'via Blog this'
Saturday, September 27, 2014
temp
http://www.cnblogs.com/zuoyuan/p/3700105.html
http://www.cnblogs.com/zzzdevil/p/3648348.html
http://www.cnblogs.com/zuoyuan/p/3703075.html
http://www.cnblogs.com/zzzdevil/p/3648348.html
http://www.cnblogs.com/zuoyuan/p/3703075.html
Thursday, September 18, 2014
Monday, September 15, 2014
LeetCode题解整理版(二) | Coding 4 Fun
LeetCode题解整理版(二) | Coding 4 Fun: " i = len(s) - 1
while i >= 0 and s[i] == ' ': i -= 1
j = i - 1
while j >= 0 and s[j] != ' ': j -= 1
return 0 if i < 0 else i - j"
'via Blog this'
while i >= 0 and s[i] == ' ': i -= 1
j = i - 1
while j >= 0 and s[j] != ' ': j -= 1
return 0 if i < 0 else i - j"
'via Blog this'
[leetcode]Implement strStr() @ Python - 南郭子綦 - 博客园
[leetcode]Implement strStr() @ Python - 南郭子綦 - 博客园: " if len(haystack) < len(needle): return None
i = 0
while i < len(haystack)-len(needle)+1:
j = 0; k = i
while j < len(needle):
if haystack[k] == needle[j]:
j+=1; k+=1
else:
break
if j == len(needle):
break
else:
i+=1
if i == len(haystack)-len(needle)+1:
return None
else:
return haystack[i:]"
'via Blog this'
i = 0
while i < len(haystack)-len(needle)+1:
j = 0; k = i
while j < len(needle):
if haystack[k] == needle[j]:
j+=1; k+=1
else:
break
if j == len(needle):
break
else:
i+=1
if i == len(haystack)-len(needle)+1:
return None
else:
return haystack[i:]"
'via Blog this'
[leetcode]Valid Palindrome @ Python - 南郭子綦 - 博客园
[leetcode]Valid Palindrome @ Python - 南郭子綦 - 博客园: " if s == '':
return True
else:
sTmp = ''
for i in range(0, len(s)):
if s[i] >= 'a' and s[i] <= 'z' or s[i] >= '0' and s[i] <= '9' or s[i] >= 'A' and s[i] <= 'Z':
sTmp += s[i]
sTmp = sTmp.lower()
for i in range(0, len(sTmp)/2):
if sTmp[i] != sTmp[len(sTmp)-1-i]:
return False
return True"
'via Blog this'
return True
else:
sTmp = ''
for i in range(0, len(s)):
if s[i] >= 'a' and s[i] <= 'z' or s[i] >= '0' and s[i] <= '9' or s[i] >= 'A' and s[i] <= 'Z':
sTmp += s[i]
sTmp = sTmp.lower()
for i in range(0, len(sTmp)/2):
if sTmp[i] != sTmp[len(sTmp)-1-i]:
return False
return True"
'via Blog this'
Sunday, September 14, 2014
[leetcode]Copy List with Random Pointer @ Python - 南郭子綦 - 博客园
[leetcode]Copy List with Random Pointer @ Python - 南郭子綦 - 博客园: "if head == None: return None
tmp = head
while tmp:
newNode = RandomListNode(tmp.label)
newNode.next = tmp.next
tmp.next = newNode
tmp = tmp.next.next
tmp = head
while tmp:
if tmp.random:
tmp.next.random = tmp.random.next
tmp = tmp.next.next
newhead = head.next
pold = head
pnew = newhead
while pnew.next:
pold.next = pnew.next
pold = pold.next
pnew.next = pold.next
pnew = pnew.next
pold.next = None
pnew.next = None
return newhead"
'via Blog this'
tmp = head
while tmp:
newNode = RandomListNode(tmp.label)
newNode.next = tmp.next
tmp.next = newNode
tmp = tmp.next.next
tmp = head
while tmp:
if tmp.random:
tmp.next.random = tmp.random.next
tmp = tmp.next.next
newhead = head.next
pold = head
pnew = newhead
while pnew.next:
pold.next = pnew.next
pold = pold.next
pnew.next = pold.next
pnew = pnew.next
pold.next = None
pnew.next = None
return newhead"
'via Blog this'
[leetcode]Swap Nodes in Pairs @ Python - 南郭子綦 - 博客园
原题地址:http://oj.leetcode.com/problems/swap-nodes-in-pairs/
题意:将链表中的节点两两交换。Given
1->2->3->4
, you should return the list as 2->1->4->3
.解题思路:这题主要涉及到链表的操作,没什么特别的技巧,注意不要出错就好。最好加一个头结点,操作起来会很方便。
代码:
# Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: # @param a ListNode # @return a ListNode def swapPairs(self, head): if head == None or head.next == None: return head dummy = ListNode(0); dummy.next = head p = dummy while p.next and p.next.next: tmp = p.next.next p.next.next = tmp.next tmp.next = p.next p.next = tmp p = p.next.next return dummy.next
Saturday, September 13, 2014
[leetcode]Remove Nth Node From End of List @ Python - 南郭子綦 - 博客园
[leetcode]Remove Nth Node From End of List @ Python - 南郭子綦 - 博客园: " dummy=ListNode(0); dummy.next=head
p1=p2=dummy
for i in range(n): p1=p1.next
while p1.next:
p1=p1.next; p2=p2.next
p2.next=p2.next.next
return dummy.next"
'via Blog this'
p1=p2=dummy
for i in range(n): p1=p1.next
while p1.next:
p1=p1.next; p2=p2.next
p2.next=p2.next.next
return dummy.next"
'via Blog this'
[leetcode]Rotate List @ Python - 南郭子綦 - 博客园
[leetcode]Rotate List @ Python - 南郭子綦 - 博客园: " if k == 0:
return head
if head == None:
return head
dummy = ListNode(0)
dummy.next = head
p = dummy
count = 0
while p.next:
p = p.next
count += 1
p.next = dummy.next
step = count - ( k % count )
for i in range(0, step):
p = p.next
head = p.next
p.next = None
return head"
'via Blog this'
return head
if head == None:
return head
dummy = ListNode(0)
dummy.next = head
p = dummy
count = 0
while p.next:
p = p.next
count += 1
p.next = dummy.next
step = count - ( k % count )
for i in range(0, step):
p = p.next
head = p.next
p.next = None
return head"
'via Blog this'
[leetcode]Plus One @ Python - 南郭子綦 - 博客园
[leetcode]Plus One @ Python - 南郭子綦 - 博客园: "class Solution:
# @param digits, a list of integer digits
# @return a list of integer digits
def plusOne(self, digits):
flag = 1
for i in range(len(digits)-1, -1, -1):
if digits[i] + flag == 10:
digits[i] = 0
flag = 1
else:
digits[i] = digits[i] + flag
flag = 0
if flag == 1:
digits.insert(0, 1)
return digits"
'via Blog this'
# @param digits, a list of integer digits
# @return a list of integer digits
def plusOne(self, digits):
flag = 1
for i in range(len(digits)-1, -1, -1):
if digits[i] + flag == 10:
digits[i] = 0
flag = 1
else:
digits[i] = digits[i] + flag
flag = 0
if flag == 1:
digits.insert(0, 1)
return digits"
'via Blog this'
Friday, September 12, 2014
How to Read Linux Top Command Output and Uses - TecAdmin.net
How to Read Linux Top Command Output and Uses - TecAdmin.net: "Using this article, I am trying to write to how to use and read results of top command."
'via Blog this'
'via Blog this'
Dropped iphone 5 in water. Help? | Apple Support Communities
Dropped iphone 5 in water. Help? | Apple Support Communities: "I used the bag of rice method this weekend and it worked. My iphone 5 had been in my pocket when I fell in our pool while cleaning the pool. So the phone was fully submerged for about 3-4 seconds. I could see water in the camera lens after this occured. It was definitely wet.
First I sucked the water out of the speaker holes with my mouth. Then I turned off the phone. Researched online and found the rice method. I put the phone in a ziplock bag with brown rice (it was all we had) about 45 minutes after the incident. A little while later I was able to find some silica gel packets in some vitamin bottles so I put those in the bag of rice with the phone (another technique found online).
The phone was in there from around 3:30 PM Saturday afternoon until 9:30 AM Monday morning. Took it out this morning and tried to turn it on but wouldn't - got the red low battery signal. After 10 minutes of charging it booted up on it's own. Works fine now. Hopefully it stays that way. By the way check your charger connector on the phone for rice. Luckily I looked before plugging it in. I tapped it on the desk and dislodged 3 pieces of rice that would have been smashed in there had I not checked first."
'via Blog this'
First I sucked the water out of the speaker holes with my mouth. Then I turned off the phone. Researched online and found the rice method. I put the phone in a ziplock bag with brown rice (it was all we had) about 45 minutes after the incident. A little while later I was able to find some silica gel packets in some vitamin bottles so I put those in the bag of rice with the phone (another technique found online).
The phone was in there from around 3:30 PM Saturday afternoon until 9:30 AM Monday morning. Took it out this morning and tried to turn it on but wouldn't - got the red low battery signal. After 10 minutes of charging it booted up on it's own. Works fine now. Hopefully it stays that way. By the way check your charger connector on the phone for rice. Luckily I looked before plugging it in. I tapped it on the desk and dislodged 3 pieces of rice that would have been smashed in there had I not checked first."
'via Blog this'
[leetcode]Permutation Sequence @ Python - 南郭子綦 - 博客园
[leetcode]Permutation Sequence @ Python - 南郭子綦 - 博客园: " res = ''
k -= 1
fac = 1
for i in range(1, n): fac *= i
num = [1, 2, 3, 4, 5, 6, 7, 8, 9]
for i in reversed(range(n)):
curr = num[k/fac]
res += str(curr)
num.remove(curr)
if i !=0:
k %= fac
fac /= i
return res"
'via Blog this'
k -= 1
fac = 1
for i in range(1, n): fac *= i
num = [1, 2, 3, 4, 5, 6, 7, 8, 9]
for i in reversed(range(n)):
curr = num[k/fac]
res += str(curr)
num.remove(curr)
if i !=0:
k %= fac
fac /= i
return res"
'via Blog this'
Monday, September 8, 2014
C++11 improvements over C++03
Source:
http://www.cplusplus.com/articles/EzywvCM9/
It supersedes the older C++03 standard, which was published in 2003.
Naturally, it brings improvements over the old standard, some of which this article will outline.
The revamped
Verbosity is bad, mainly because it makes your code less clear.
So the
Example:
Bad example:
Range-based
Iterating over the contents of STL containers is a very common operation.
C++11 now provides a specialized
It also works on plain C arrays.
Example:
Example:
Initializer lists can also be used for more complex structures.
Example:
This is more of an addition than an improvement, but I decided to include it in the article anyway.
C++11 provides
Example:
The GNU C++ compiler requires the commandline parameter -std=c++0x to compile C++11 code.
Microsoft Visual Studio 2010 has partial support for C++11 features, out of the box.
Microsoft Visual Studio 201x (v11) will still only have partial support for C++11 features.
http://www.cplusplus.com/articles/EzywvCM9/
About C++11
C++11 aka C++0x is the new standard of the C++ language, published in late 2011.It supersedes the older C++03 standard, which was published in 2003.
Naturally, it brings improvements over the old standard, some of which this article will outline.
The revamped auto
keyword
Verbosity is bad, mainly because it makes your code less clear.So the
auto
keyword, a leftover from C, got a new meaning in C++11: automatic type deduction.Example:
|
|
Bad example:
|
|
Range-based for()
Iterating over the contents of STL containers is a very common operation.C++11 now provides a specialized
for()
which can iterate over anything that has a begin()
and an end()
member function, which return the expected iterators.It also works on plain C arrays.
Example:
|
|
Initializer lists
The containers in C++03 could not be initialized as "naturally" as good old C-style arrays. That has changed.Example:
|
|
Initializer lists can also be used for more complex structures.
Example:
|
|
C++ arrays
This is more of an addition than an improvement, but I decided to include it in the article anyway.
C++11 provides
std::array
, which has the purpose of replacing C arrays. It is a fixed-sized, lightweight alternative to the dynamically-sized std::vector
.Example:
|
|
Minor fixes
C++03 had a bunch of minor glitches and design flaws which were fixed in C++11:- Things like
set<vector<int>>
finally compile.
Notice the lack of space between the last two angle brackets. std::string
now hasfront()
andback()
member functions.- File streams now accept an
std::string
as filename.
This means one less use for the ridiculousc_str()
member function. - Easy conversion of numerical values to
std::string
is now possible through the use of the overloaded functions:
string to_string(int)
string to_string(float)
string to_string(double)
...
Compiler support for C++11
... is not too bad. But give it a year or two to set.The GNU C++ compiler requires the commandline parameter -std=c++0x to compile C++11 code.
Microsoft Visual Studio 2010 has partial support for C++11 features, out of the box.
Microsoft Visual Studio 201x (v11) will still only have partial support for C++11 features.
Sunday, September 7, 2014
Saturday, September 6, 2014
Friday, September 5, 2014
Thursday, September 4, 2014
Wednesday, September 3, 2014
c++ - Compiling C++11 with g++
http://stackoverflow.com/questions/10363646/compiling-c11-with-g
Flags (or compiler options) are nothing but ordinary command line arguments passed to the compiler executable.
Assuming you are invoking g++ from the command line (terminal):
$ g++ -std=c++11 your_file.cpp -o your_program
or
$ g++ -std=c++0x your_file.cpp -o your_program
if the above doesn't work.
Subscribe to:
Posts (Atom)