标签:api turn 传参 es2017 inter enc run get i++
简单的思路:
深度优先搜索:
class Solution {
public:
bool isPalin(string str)
{
int n=str.length();
int i=0;
int j=n-1;
while(i<j)
{
if(str[i]==str[j])
{
i++;
j--;
}
else
return false;
}
return true;
}
void getPart(string s, vector<vector<string>>& result, vector<string> temp)
{
if(s.length()==0)
{
result.push_back(temp);
return;
}
string str1;
string str2;
for(int i=1;i<=s.length();i++)
{
str1=s.substr(0,i);
// cout<<str1<<endl;
if(isPalin(str1))
{
str2=s.substr(i);
// cout<<str2<<endl;
temp.push_back(str1);
getPart(str2, result, temp);
temp.pop_back();
}
}
}
vector<vector<string>> partition(string s) {
vector<vector<string>> result;
vector<string> temp;
getPart(s, result, temp);
return result;
}
};
python
class Solution(object):
def isPalin(self, s):
n=len(s)-1
m=0
while(m<n):
if(s[m]!=s[n]):
return False
else:
m+=1
n-=1
return True
def dfs(self,s, stringlist):
if len(s)==0: Solution.result.append(stringlist)
for i in range(1, len(s)+1):
if(self.isPalin(s[:i])):
self.dfs(s[i:],stringlist+[s[:i]])
def partition(self, s):
"""
:type s: str
:rtype: List[List[str]]
"""
Solution.result=[]
self.dfs(s,[])
return Solution.result
python 中传参数?

def changeI(c):
c=10
if __name__=="__main__":
# nums=[100, 4, 200,1,3,2]
# s=Solution()
# c=s.longestConsecutive(nums)
a=2
changeI(a)
print(a)
a 输出依然为2,对于一个int 对象2, 和指向它的变量a, 值传递,复制了变量a的值。a,c 指向同一个int 对象,c=10,int 不能改变,生成一个新的int 对象,c指向这个新对象,a指向的对象没有变化。
def changeI(c):
c[0]=10
if __name__=="__main__":
# nums=[100, 4, 200,1,3,2]
# s=Solution()
# c=s.longestConsecutive(nums)
a=[2]
changeI(a)
print(a[0])
输出10,变量依旧是传值,复制a的值,a和c 指向同一个对象,但是list 可改变对象,对 c[0]的操作,就是对a的操作。
python 中的string类型?
回 True,否则返回 False
python 中的list 类型?
python 中的set 类型?
python 中的in? range 的范围?
python 中的self?
leetcode 131. Palindrome Partitioning
标签:api turn 传参 es2017 inter enc run get i++
原文地址:http://www.cnblogs.com/fanhaha/p/7406011.html