07 2019 档案

摘要:一开始写的: # # @lc app=leetcode.cn id=114 lang=python3 # # [114] 二叉树展开为链表 # # Definition for a binary tree node. # class TreeNode: # def __init__(self, x) 阅读全文
posted @ 2019-07-29 15:29 NeoZy 阅读(136) 评论(0) 推荐(0)
摘要:105. 从前序与中序遍历序列构造二叉树 2020/2/17: C++: 1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode 阅读全文
posted @ 2019-07-27 22:04 NeoZy 阅读(168) 评论(0) 推荐(0)
摘要:两种方法: 1.递归,每个节点递归时都会有一个上下界,越往下遍历节点的上下界会越来越收紧,若有不在上下界内的就返回False,最初对根节点的上下界没有,那就默认为负无穷到正无穷。 Definition for a binary tree node. # class TreeNode: # def _ 阅读全文
posted @ 2019-07-27 21:09 NeoZy 阅读(115) 评论(0) 推荐(0)
摘要:题目 给定一个只包含数字的字符串,复原它并返回所有可能的 IP 地址格式。 示例: 输入: "25525511135" 输出: ["255.255.11.135", "255.255.111.35"] 想法就是回溯,不过因为俺是python新手,好几个小问题出错导致结果一直不对 1.strip()、 阅读全文
posted @ 2019-07-26 23:08 NeoZy 阅读(211) 评论(0) 推荐(0)
摘要:#include#include#inclu... 阅读全文
posted @ 2019-07-16 14:42 NeoZy 阅读(192) 评论(0) 推荐(0)
摘要:开始想到了转字符串再比较,但没想到x+y>y... 阅读全文
posted @ 2019-07-14 21:01 NeoZy 阅读(81) 评论(0) 推荐(0)
摘要:开始想的是计数排序,但超时,如[2,999999999]这样的样例,记录数组太长,有用的占比太少。后看官方思路,用n+1(n为原数组元素个数)个桶去筛元素,每个桶能放的元素大小范围固定,即下面代码中的step,处理完后再扫描一遍当前桶最大和后继桶最小值的差,取最大差值为结果。至于为什么要n+1个桶, 阅读全文
posted @ 2019-07-13 21:41 NeoZy 阅读(147) 评论(0) 推荐(0)
摘要:参考 https://www.cnblogs.com/jclian91/p/9151120.html 1.暴力算法 O(n^2) def maximum_subarray_1(nums): siz=len(nums) res=0 for i in range(siz): sum=0 for j in 阅读全文
posted @ 2019-07-07 15:11 NeoZy 阅读(153) 评论(0) 推荐(0)
摘要:放假没事干,复习复习,有空再用python写一遍 #include<iostream> #include<math.h> #include<Windows.h> #include<vector> #include<time.h> using namespace std; //冒泡排序 void Bu 阅读全文
posted @ 2019-07-05 00:51 NeoZy 阅读(129) 评论(0) 推荐(0)
摘要:python 前面加个dummy节点,这样就不用考虑头节点的更新问题了 # Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None 阅读全文
posted @ 2019-07-02 19:10 NeoZy 阅读(72) 评论(0) 推荐(0)
摘要:俺的: class Solution: def removeDuplicates(self, nums: List[int]) -> int: if(len(nums)==0): return 0 i=0 while i<len(nums): s=i while i<len(nums) and nu 阅读全文
posted @ 2019-07-02 18:22 NeoZy 阅读(78) 评论(0) 推荐(0)