摘要:
Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum. Example: Inpu 阅读全文
摘要:
Write an algorithm to determine if a number is "happy". A happy number is a number defined by the following process: Starting with any positive intege 阅读全文
摘要:
从今天开始努力刷题,用这个帖子来记录刷题的进度。也方便自己的寻找。 题号 题目 复习 1 Two Sum Y 2 Add Two Numbers Y 3 Longest Substring Without Repeating Characters Y 4 Median of Two Sorted A 阅读全文
摘要:
Given a non-empty array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runti 阅读全文
摘要:
这道题虽然简单,但是需要注意的点还是比较多,首先是如果一直有重复的duplicate,要把所有的都去掉,所以inner loop是while而不是if,其次是每一层loop结束的条件,要搞清楚是head,还是head.next是不是None。 最后学习一下在python中如何建立一个class并且写 阅读全文
摘要:
很简单的杨辉三角问题,时间复杂度是O(N), 空间复杂度是O(1) class Solution: def generate(self, numRows: int) -> List[List[int]]: if numRows == 0: return [] result = [[1]] for r 阅读全文
摘要:
这道题其实和其他类似问题很相似,就是要处理carry的问题。时间复杂度是O(N),空间复杂度是O(1) class Solution: def addBinary(self, a: str, b: str) -> str: i, j, carry = len(a) - 1, len(b) - 1, 阅读全文
摘要:
这道题非常简单,就是双指针问题的基础版,时间复杂度是O(N),空间复杂度是O(1) class Solution: def reverseString(self, s: List[str]) -> None: """ Do not return anything, modify s in-place 阅读全文
摘要:
这道题的时间复杂度是O(N), 空间复杂度也是O(N) 这道题也是matrix的遍历,只是遍历的顺序是sprial,这种题的模版就是写出变化的delta,然后check新的点是不是在matrix的范围内,加上其他条件,这道题的条件是是否已经visit过,当满足就会发生一些变化,比如方向的变化。还有一 阅读全文
摘要:
我的思路是很简单的,就是从后往前,加一个carry。 大家的思路都是先求出数值,直接+1,然后再转化成list,用str和int cast实现,以下是leetcode里面的几个典型写法 https://leetcode.com/problems/plus-one/discuss/24085/Simp 阅读全文