- 博客(124)
- 收藏
- 关注
原创 java学习笔记
基础语法类名首字母大写 方法名首字母小写,多个单词后的每个单词首字母大写对象和类对象是类的一个实例,有状态和行为,状态是静止的,比如颜色,名字,行为是动态的,比如摇尾巴;类是一个模版,描述对象的行为和状态 每个类都有构造方法,若没有显式定义,则编译器会提供一个默认构造方法 在创建对象时,至少要调用一个构造方法,其与类名同名。构造方法可有多个 访问类中的方法:对象.方法名();访问变量:对象.变量名; 一个源文件中只能有一个public类,可有多个非public类 ...
2022-05-23 21:17:40
97
原创 leetcode第51题(validate-binary-search-tree)
题目:Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than the
2018-02-09 21:01:49
294
原创 leetcode第50题(recover-binary-search-tree)
题目:Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing its structure. Note: A solution using O(n ) space is pretty straight forward. Coul
2018-02-09 20:46:59
276
原创 leetcode第49题(same-tree)
题目:Given two binary trees, write a function to check if they are equal or not. Two binary trees are considered equal if they are structurally identical and the nodes have the same value.
2018-02-09 16:41:17
222
原创 leetcode第48题(symmetric-tree)
题目:Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3
2018-02-09 16:33:37
204
原创 leetcode第47题(binary-tree-level-order-traversal)
题目:Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). For example:Given binary tree{3,9,20,#,#,15,7}, 3 / \
2018-02-09 16:15:00
258
原创 leetcode第46题(binary-tree-zigzag-level-order-traversal)
题目:Given a binary tree, return the zigzag level ordertraversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between). For example:Give
2018-02-09 16:00:15
159
原创 leetcode第45题(maximum-depth-of-binary-tree)
题目:Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. 思路:递归的计算左子树和右子树的深度,然后返回
2018-02-09 15:42:09
276
原创 leetcode第44题(construct-binary-tree-from-preorder-and-inorder-……)
题目:Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree.思路:前序遍历是根左右,中序遍历是左根右,第一个节点是跟,中序中根的左边为左子树,根
2018-02-09 15:29:08
194
原创 leetcode第43题(binary-tree-level-order-traversal)
题目:Given inorder and postorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree. 思路:中序遍历的顺序:左根右,后序遍历的顺序:左右根。因而我们可以找到最后一
2018-02-09 14:15:13
175
原创 leetcode第42题(binary-tree-level-order-traversal-ii)
题目:Given a binary tree, return the bottom-up level ordertraversal of its nodes' values. (ie, from left to right, level by level from leaf to root). For example:Given binary tree{3,9,20,#,#
2018-02-09 14:11:37
164
原创 leetcode第41题(convert-sorted-array-to-binary-search-tree)
题目:Given an array where elements are sorted in ascending order, convert it to a height balanced BST.思路:跟上题的思路一样,但这题更简单,因为数组可以随便取到中间的值,不需要通过快慢指针。代码:/** * Definition for binary tree * pu
2018-02-08 21:04:49
165
原创 leetcode第40题(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.思路:链接:https://www.nowcoder.net/questionTerminal/86343165c18a4069ab0ab30c32b1afd0
2018-02-08 20:49:30
233
原创 leetcode第39题(balanced-binary-tree)
题目:Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node n
2018-02-08 20:19:18
162
原创 leetcode第38题(path-sum)
题目:Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum. For example:Given the below binary tree
2018-02-08 19:46:23
209
原创 leetcode第37题(path-sum-ii)
题目:Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum. For example:Given the below binary tree andsum = 22, 5
2018-02-08 19:44:13
184
原创 leetcode第36题(distinct-subsequences)
题目:Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence of a string is a new string which is formed from the original string by deleting some (ca
2018-02-08 16:18:04
152
原创 leetcode第34.35题(populating-next-right-pointers-in-each-node)
题目:Follow up for problem "Populating Next Right Pointers in Each Node". What if the given tree could be any binary tree? Would your previous solution still work? Note:You may only
2018-02-08 15:37:22
167
原创 leetcode第33题(pascals-triangle)
题目:Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,思路:下一行数据是上一行两个相邻数相加。代码:til.ArrayList;public class Solution { public Arra
2018-02-07 21:16:41
234
原创 leetcode第32题(pascals-triangle-ii)
题目:Given an index k, return the k th row of the Pascal's triangle. For example, given k = 3,Return[1,3,3,1]. Note: Could you optimize your algorithm to use only O(k) extra space?
2018-02-07 21:13:40
183
原创 leetcode第31题(triangle)
题目:Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below. For example, given the following triangle [ [2], [3,4
2018-02-07 20:18:02
200
原创 leetcode第30题(best-time-to-buy-and-sell-stock)
题目:Say you have an array for which the i th element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (ie, buy one and sell one share of
2018-02-06 16:55:32
188
原创 leetcode第29题(best-time-to-buy-and-sell-stock-ii)
题目:Say you have an array for which the i th element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete as many transactions as you like (i
2018-02-06 16:52:59
269
原创 leetcode第28题(best-time-to-buy-and-sell-stock-iii)
题目:Say you have an array for which the i th element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete at most two transactions. Note:
2018-02-06 16:50:29
351
原创 leetcode第27题(binary-tree-maximum-path-sum)
题目:Given a binary tree, find the maximum path sum. The path may start and end at any node in the tree. For example:Given the below binary tree, 1 / \ 2 3
2018-02-05 21:13:41
126
原创 leetcode第26题(valid-palindrome)
题目:Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example,"A man, a plan, a canal: Panama"is a palindrome."race a car"is
2018-02-05 15:34:48
180
原创 leetcode第23题(longest-consecutive-sequence)
题目:Given an unsorted array of integers, find the length of the longest consecutive elements sequence. For example,Given[100, 4, 200, 1, 3, 2],The longest consecutive elements sequence is
2018-01-19 16:59:15
219
原创 leetcode第22题(sum-root-to-leaf-numbers)
题目:Given a binary tree containing digits from0-9only, each root-to-leaf path could represent a number. An example is the root-to-leaf path1->2->3which represents the number123. Find the
2018-01-19 15:27:36
184
原创 surrounded-regions
题目:Given a 2D board containing'X'and'O', capture all regions surrounded by'X'. A region is captured by flipping all'O's into'X's in that surrounded region . For example, X X X XX O O
2018-01-19 15:03:17
231
原创 leetcode第20题(palindrome-partitioning)
题目:Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. For example, given s ="aab",Return [
2018-01-17 20:53:25
200
原创 leetcode第19题(palindrome-partitioning-ii)
题目:Given a string s, partition s such that every substring of the partition is a palindrome. Return the minimum cuts needed for a palindrome partitioning of s. For example, given s ="aab",Return1since
2018-01-17 20:25:49
230
原创 leetcode第18题(clone-graph)
题目:Clone an undirected graph. Each node in the graph contains alabeland a list of itsneighbors. OJ's undirected graph serialization:Nodes are labeled uniquely. We use#as a separator fo
2018-01-15 15:00:15
173
原创 leetcode第17题(gas_station)
题目:There are N gas stations along a circular route, where the amount of gas at station i isgas[i]. You have a car with an unlimited gas tank and it costscost[i]of gas to travel from station i
2018-01-15 13:58:05
204
原创 leetcode第16题(candy)
题目:There are N children standing in a line. Each child is assigned a rating value. You are giving candies to these children subjected to the following requirements: Each child must have at
2018-01-15 13:22:35
229
原创 leetcode第15题(single-number)
题目:Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without
2018-01-14 20:28:35
178
原创 leetcode第14题(single-number-ii)
题目:Given an array of integers, every element appears three times except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it wi
2018-01-14 20:21:17
215
原创 leetcode第13题(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. 思路:跟剑指offer25道题一样代码:
2018-01-14 19:34:54
120
原创 leetcode第12题(word-break)
题目:Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words. For example, givens ="leetcode",dict =[
2018-01-14 18:52:37
184
原创 leetcode第11题(word-break-ii)
题目:Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences. For example, giv
2018-01-14 18:24:41
215
原创 leetcode第10题(linked-list-cycle)
题目:Given a linked list, determine if it has a cycle in it. Follow up:Can you solve it without using extra space?思路:跟上面题一样,只是不用求相遇点,第一次相遇就可以判断有环。代码:/** * Definition for singly-
2018-01-14 14:56:47
162
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人