
leetcode
文章平均质量分 51
Jason__Liang
哈尔滨工业大学(威海)14级电子科学与技术学生,写博客的目的是为了记录现在幼稚的代码,并希望有一天能在我面试的时候发挥作用。
展开
-
leetcode 806. 写字符串需要的行数
class Solution(object): def numberOfLines(self, widths, S): """ :type widths: List[int] :type S: str :rtype: List[int] """ base=ord('a') #字母a的作...原创 2018-03-29 19:34:36 · 634 阅读 · 0 评论 -
Leetcode 404. 左叶子之和
这道题看到了解法又让我感受到了编程之美。教会了我虽然框架能让人很快写出代码,但是真正优秀的代码总是能够不被框架约束!参考了向北的稻草 的博客class Solution: def sumOfLeftLeaves(self, root): """ :type root: TreeNode :rtype: int """ ...原创 2018-04-03 16:09:12 · 729 阅读 · 0 评论 -
leetcode 657. 判断路线成圈
我用了字典的方式来做这题,挺好玩的题目class Solution: def judgeCircle(self, moves): """ :type moves: str :rtype: bool """ dict={"U":(0,1), "D":(0,-1), ...原创 2018-03-27 22:20:28 · 363 阅读 · 0 评论 -
leetcode 766. 托普利茨矩阵
class Solution: def isToeplitzMatrix(self, matrix): """ :type matrix: List[List[int]] :rtype: bool """ m=len(matrix) n=len(matrix[0]) for i ...原创 2018-03-27 20:22:54 · 645 阅读 · 0 评论 -
leetcode 205. 同构字符串
class Solution: def isIsomorphic(self, s, t): """ :type s: str :type t: str :rtype: boo """ if len(s) != len(t): return False d...原创 2018-04-01 20:45:28 · 362 阅读 · 0 评论 -
Leetcode 606. 根据二叉树创建字符串
一定要理清逻辑,我在这题上修修补补,打补丁打了半天,最后才发现,如果一开始有清晰的逻辑的话,那么代码会非常简单的。class Solution: def tree2str(self,t): if t is None: return "" s=str(t.val) a=self.tree2str(t.left) ...原创 2018-04-01 12:00:40 · 625 阅读 · 0 评论 -
Leetcode 38. 数数并说
class Solution: def countAndSay(self, n): """ :type n: int :rtype: str """ S="1" for i in range(1,n): #控制外层的迭代次数 S=self.myfun(S) ...原创 2018-03-31 13:55:48 · 975 阅读 · 0 评论 -
python leetcode 258. 各位相加
人生苦短,我用python我感觉我这种做法太邪恶了。。。class Solution: def addDigits(self, num): """ :type num: int :rtype: int """ num=str(num)#变成字符串来进行处理 count=0 whi...原创 2018-03-30 19:34:26 · 369 阅读 · 0 评论 -
leetcode 171. Excel表列序号
#思路就是26进制转10进制,这样一说是不是感觉很简单了呢?class Solution(object): def titleToNumber(self, s): """ :type s: str :rtype: int """ base=ord("A")-1 count=0 f...原创 2018-03-30 17:13:03 · 278 阅读 · 0 评论 -
leetcode 575. 分糖果
class Solution(object): def distributeCandies(self, candies): """ :type candies: List[int] :rtype: int """ myset=set()#表示多少种类 for i in candies: ...原创 2018-03-30 16:58:11 · 631 阅读 · 0 评论 -
leetcode 669. 修剪二叉搜索树
class Solution(object): def trimBST(self, root, L, R): """ :type root: TreeNode :type L: int :type R: int :rtype: TreeNode """ if root is ...原创 2018-03-30 09:36:43 · 679 阅读 · 0 评论