- 博客(6)
- 收藏
- 关注
原创 [Leetcode]Container with most water 最大容水量
问题:Given n non-negative integers a1, a2, …, an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find t...
2019-08-01 10:54:03 121
原创 Leetcode: 反转32-bit整数
真的没意思的一道题,刚开始还想用stack做,后来只能感叹python的强大,直接反转字符串,核心代码就是[::-1]class Solution: def reverse(self, x: int) -> int: if x > -10 and x < 10: return x sign = 1 ...
2019-05-21 11:05:11 435
原创 Leetcode: Zigzag conversion
没啥技术含量的一道题。。。刚开始想用数学的方法找规律的,2n-2什么的,后来觉得python的一些特性挺适合这道题的class Solution: def convert(self, s: str, numRows: int) -> str: if (numRows >= len(s) or numRows==1): return s...
2019-05-18 19:21:01 128
原创 Leetcode 找最大回文子字符串
用动态规划做。思路很简单,maintain一个dp的二维数组,里面记录dp[i][j]的状态:true就是从I到j 的子字符串是palindrome。分base和recursive case:base就是substring的长度是1或2,直接比较s[i]和s[j],recursive:如果s[i]等于s[j] 并且s[i+1][j-1]也是palindrome,则设 dp[i][j]为true。...
2019-05-17 16:45:28 159
原创 Leetcode 找最长不重复子字符串
Given a string, find the length of the longest substring without repeating characters.Example 1:Input: “abcabcbb”Output: 3Explanation: The answer is “abc”, with the length of 3.Example 2:Input: ...
2019-05-17 00:59:00 281
原创 Leetcode 用链表相加两个数
Leetcode 用链表相加两个数You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two nu...
2019-05-17 00:38:08 253
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人