
leetcode
likyoo
You can visit https://github.com/likyoo for more information.
展开
-
leetcode 53. 最大子序和
// 贪心法class Solution {public: int maxSubArray(vector<int>& nums) { int maxnum, sum; int i, flag = 1; for(i = 0; i < size(nums); i++){ if(i == ...原创 2020-02-27 23:00:54 · 104 阅读 · 0 评论 -
leetcode 21 合并两个有序链表
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNo...原创 2020-02-23 16:08:23 · 142 阅读 · 0 评论 -
leetcode 3 无重复字符的最长子串
c++:class Solution {public: int lengthOfLongestSubstring(string s) { if(s == "") return 0; int head = 0; int num = 0, p = 0; for(int i = 0; i < s.size(); i...原创 2020-01-03 20:25:16 · 124 阅读 · 0 评论 -
leetcode 2 两数相加
c++:// c++/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {p...原创 2020-01-01 22:18:10 · 100 阅读 · 0 评论 -
Leetcode Medium 5 Letter Combinations of a Phone Number
不用递归 class Solution: def letterCombinations(self, digits): dic = {'2':'abc', '3':'def','4':'ghi', '5':'jkl', '6':'mno', '7':'pqrs', '8':'tuv', '9':'wxyz'} if not digits: ...原创 2019-01-22 17:16:48 · 123 阅读 · 0 评论 -
Leetcode Easy 3 Palindrome Number
1.class Solution: def isPalindrome(self, x): s = str(x) s_ = s[::-1] if s == s_: return True else: return False2.class Solution: ...原创 2019-01-20 22:38:11 · 210 阅读 · 0 评论 -
Leetcode Medium 4 Container With Most Water
class Solution: def maxArea(self, height): max_pool = 0 i, j = 0, len(height)-1 while i < j: if height[i] < height[j]: max_pool = max(max...原创 2019-01-14 22:29:15 · 123 阅读 · 0 评论 -
Leetcode Easy 2 Roman to Integer
class Solution: def romanToInt(self, s): # if s == '': # return 0 def compare(a, b): if dic[a] >= dic[b]: return dic[a] else...原创 2019-01-18 23:57:37 · 121 阅读 · 0 评论 -
Leetcode Medium 3 Longest Substring Without Repeating Characters
用滑动窗口 class Solution: def lengthOfLongestSubstring(self, s): i, j, ans = 0, 0, 0 len_s = len(s) max_str = '' while j < len_s: if not s[j] in max_s...原创 2019-01-13 23:47:56 · 115 阅读 · 0 评论 -
Leetcode Medium 2 String to Integer (atoi)
class Solution: def myAtoi(self, str): s = '' str = str.lstrip() for i in range(len(str)): if str[i].isdigit() or ((str[i] == '+' or str[i] == '-') and i == 0)...原创 2019-01-12 23:29:54 · 121 阅读 · 0 评论 -
Leetcode Easy 1 Reverse Integer
class Solution: def reverse(self, x): if x >= 0: s = str(x) s = s[::-1] else: s = str(-x) s = s[::-1] s = '-' + s ...原创 2019-01-12 21:41:08 · 147 阅读 · 0 评论 -
Leetcode Medium 1 3Sum Closest
可惜就弄到了168 ms 64%:思路:先排序。i, j, k 分别代表相加的三个数。 i 开始循环, j 和 k 分别从 i+1 的位置和nums尾部互相靠拢(如果大于target:k-- ; 否则,j++)class Solution: def threeSumClosest(self, nums, target): nums.so...原创 2018-11-27 22:01:01 · 130 阅读 · 0 评论 -
Leetcode Medium 0 ZigZag Conversion
第一次 196ms 18%:class Solution: def convert(self, s, numRows): l = [] r = '' for i in range(numRows): l.append([]) pos = -1 forword = True ...原创 2018-11-25 20:23:19 · 110 阅读 · 0 评论 -
Leetcode Easy 0 Two Sum
第一次,超时class Solution(object): def twoSum(self, nums, target): for i in range(len(nums)): for j in range(i+1,len(nums)): if(nums[i] + nums[j] == target): ...原创 2018-11-24 10:18:37 · 136 阅读 · 0 评论