- 博客(170)
- 收藏
- 关注

原创 开博flag
今天是2019.3.22,距离提交完所有学校的申请已经过去两个半月,除去过年的一个月以及陪moomin的半个月,业已花费了一个月的时间沉浸在焦虑与自我否定中无法自拔。大家都说今年计算机的申请又变难了,结果也出得比较慢,但目前只收到了一枚保底校ad的本人主要还是能力不够。经过一个月的自我否定,已经做好了只能去保底校的准备,并打算做一只保底校的大牛。过去的一个月基本上什么也没做,但好在也不是完全颓...
2019-10-16 22:20:00
213
原创 刷题常用Java复习
这里写自定义目录标题欢迎使用Markdown编辑器新的改变功能快捷键合理的创建标题,有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释也是必不可少的KaTeX数学公式新的甘特图功能,丰富你的文章UML 图表FLowchart流程图导出与导入导出导入欢迎使用Markdown编辑器你好! 这是你第一次使用 Markdown编辑器 所展示的欢迎页。如果你想学习如何使用Mar
2020-07-19 07:27:03
232
原创 572. Subtree of Another Tree
题目Given two non-empty binary trees s and t, check whether tree t has exactly the same structure and node values with a subtree of s. A subtree of s is a tree consists of a node in s and all of this n...
2019-12-09 00:14:58
171
原创 560. Subarray Sum Equals K
题目Given an array of integers and an integer k, you need to find the total number of continuous subarrays whose sum equals to k.Example 1:Input:nums = [1,1,1], k = 2Output: 2Note:The length of th...
2019-12-08 23:33:39
186
原创 543. Diameter of Binary Tree
题目Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any two nodes in a tree. This path may or ma...
2019-12-07 06:45:08
135
原创 503. Next Greater Element II
题目Given a circular array (the next element of the last element is the first element of the array), print the Next Greater Number for every element. The Next Greater Number of a number x is the first ...
2019-12-07 05:47:09
137
原创 347. Top K Frequent Elements
题目Given a non-empty array of integers, return the k most frequent elements.Example 1:Input: nums = [1,1,1,2,2,3], k = 2Output: [1,2]我的想法用HashMap存频率,再根据频数进行快速排序或者归并排序。但不知道怎样存元素,class Solution {...
2019-12-07 00:57:12
148
原创 350. Intersection of Two Arrays II
题目Given two arrays, write a function to compute their intersection.Example 1:Input: nums1 = [1,2,2,1], nums2 = [2,2]Output: [2,2]Example 2:Input: nums1 = [4,9,5], nums2 = [9,4,9,8,4]Output: [4,...
2019-12-06 08:40:43
88
原创 148. Sort List
题目Sort a linked list in O(n log n) time using constant space complexity.Example 1:Input: 4->2->1->3Output: 1->2->3->4我的想法感觉用归并排序不会太复杂,但是实际写的时候越写越晕。以下代码并不对,只是为了记录class Solutio...
2019-12-06 01:21:23
126
原创 912. Sort an Array
题目Given an array of integers nums, sort the array in ascending order.我的想法快排模板注意!!!为了使左右指针错开,以防止死循环,快排的所有判断都要带等号!class Solution { public List<Integer> sortArray(int[] nums) { qui...
2019-12-05 10:37:39
102
原创 138. Copy List with Random Pointer
题目A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list.我的想法在循环建立新链表的时候,用一个hashmap存入所有新建...
2019-12-05 01:30:05
96
原创 116. Populating Next Right Pointers in Each Node
题目You are given a perfect binary tree where all leaves are on the same level, and every parent has two children. The binary tree has the following definition:struct Node { int val; Node *left; ...
2019-12-05 01:04:25
106
原创 109. Convert Sorted List to Binary Search Tree
题目Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.For this problem, a height-balanced binary tree is defined as a binary tree in which th...
2019-12-04 12:06:38
106
原创 103. Binary Tree Zigzag Level Order Traversal
题目Given a binary tree, return the zigzag level order traversal of its nodes’ values. (ie, from left to right, then right to left for the next level and alternate between).我的想法层级遍历二叉树,逢偶倒转listclass...
2019-12-04 08:47:09
108
原创 76. Minimum Window Substring
题目Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).Example:Input: S = “ADOBECODEBANC”, T = “ABC”Output: “BANC”Note:If t...
2019-12-04 07:51:57
95
原创 101. Symmetric Tree
题目Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \3 4 4 3B...
2019-12-04 06:18:52
89
原创 240. Search a 2D Matrix II
题目Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted in ascending from left to right.Integers in eac...
2019-12-02 00:35:44
102
原创 448. Find All Numbers Disappeared in an Array
题目Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements of [1, n] inclusive that do not appear in this array.Cou...
2019-11-28 04:42:12
105
原创 212. Word Search II
题目Given a 2D board and a list of words from the dictionary, find all words in the board.Each word must be constructed from letters of sequentially adjacent cell, where “adjacent” cells are those hor...
2019-11-27 08:58:51
119
原创 215. Kth Largest Element in an Array
题目Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.我的想法没太懂,感觉就是个排序的问题,为什么能算mediumclass Solution { pu...
2019-11-27 05:51:15
115
原创 139. Word Break
题目Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words.Note:Th...
2019-11-27 01:00:10
96
原创 472. Concatenated Words
题目Given a list of words (without duplicates), please write a program that returns all concatenated words in the given list of words.A concatenated word is defined as a string that is comprised entir...
2019-11-26 06:12:17
98
原创 545. Boundary of Binary Tree
题目Given a binary tree, return the values of its boundary in anti-clockwise direction starting from root. Boundary includes left boundary, leaves, and right boundary in order without duplicate nodes....
2019-11-26 01:34:58
125
原创 155. Min Stack
题目Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) – Push element x onto stack.pop() – Removes the element on top of the stack.top() – Get t...
2019-11-24 08:37:30
109
原创 173. Binary Search Tree Iterator
题目Design an iterator over a binary search tree with the following rules:Elements are visited in ascending order (i.e. an in-order traversal)next() and hasNext() queries run in O(1) time in average....
2019-11-24 08:01:42
83
原创 272. Closest Binary Search Tree Value II
题目Given a non-empty binary search tree and a target value, find k values in the BST that are closest to the target.Example 1:Input:{1}0.0000001Output:[1]我的想法跟二分法的658. Find K Closest Elements...
2019-11-24 06:51:33
134
原创 680. Valid Palindrome II
题目Given a non-empty string s, you may delete at most one character. Judge whether you can make it a palindrome.Example 1:Input: “aba”Output: TrueNote:The string will only contain lowercase chara...
2019-11-16 01:21:17
85
原创 160. Intersection of Two Linked Lists
题目Write a program to find the node at which the intersection of two singly linked lists begins.Notes:If the two linked lists have no intersection at all, return null.The linked lists must retain ...
2019-11-15 08:45:00
107
原创 202. Happy Number
题目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 integer, replace the number by the sum of the squares...
2019-11-14 21:46:23
99
原创 56. Merge Intervals
题目Given a collection of intervals, merge all overlapping intervals.Example 1:Input: [[1,3],[2,6],[8,10],[15,18]]Output: [[1,6],[8,10],[15,18]]Explanation: Since intervals [1,3] and [2,6] overlaps...
2019-11-12 23:35:10
101
原创 238. Product of Array Except Self
题目Given an array nums of n integers where n > 1, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Example:Input: [1,2,3,4]Output: ...
2019-11-12 05:07:43
100
原创 21. Merge Two Sorted Lists
题目Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.我的想法注意是把旧的node连接起来,不能new新的点。l1和l2长度不一定相等,最后记得把l1或者l2剩下...
2019-11-11 23:25:25
87
原创 15. 3Sum
题目Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:The solution set must not con...
2019-11-11 22:59:39
96
原创 53. Maximum Subarray
题目Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.Example:Input: [-2,1,-3,4,-1,2,1,-5,4],Output: 6Explanati...
2019-11-11 11:42:56
105
原创 4. Median of Two Sorted Arrays
题目There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).You may assume nums1 and ...
2019-11-11 05:21:35
86
原创 146. LRU Cache
题目Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put.get(key) - Get the value (will always be positive) of the key if ...
2019-11-08 10:20:35
114
原创 270 Closest Binary Search Tree Value
题目Given a non-empty binary search tree and a target value, find the value in the BST that is closest to the target.我的想法最开始的想法是,当前结点的差值与左右子结点的差值比较,如果当前最小则输出当前,否则将当前结点设为较小的那个点,在继续循环。但是这样有个问题,当前最小并不一定...
2019-10-22 10:28:01
116
原创 114. Flatten Binary Tree to Linked List
题目Given a binary tree, flatten it to a linked list in-place.我的想法定义一个全局变量lastNode来存储前序遍历的最后一个结点,每次只需要把右子树的点接在lastNode后面即可。实现起来觉得很绕,写不出。class Solution { TreeNode lastNode; public void flatte...
2019-10-22 00:36:14
110
原创 236. Lowest Common Ancestor of a Binary Tree
题目Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes ...
2019-10-19 01:13:54
94
原创 257. Binary Tree Paths
题目Given a binary tree, return all root-to-leaf paths.我的想法遍历法,需要注意不能在root == null时把结果加入list,这样会重复计算,而且并没有走到真正的叶子结点(缺少一边的子树也会输出,但实际上这并不是叶子结点)public class Solution { public List<String> bin...
2019-10-18 22:59:20
139
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人