Java
林下溪源
为学日益,为道日损
展开
-
68. Text Justification
Problem Description:Given an array of words and a widthmaxWidth, format the text such that each line has exactlymaxWidthcharacters and is fully (left and right) justified.You should pack your words in a greedy approach; that is, pack as many words ...原创 2020-09-03 19:05:51 · 190 阅读 · 0 评论 -
67. Add Binary
Problem Description:67.Add BinaryEasy1983285Add to ListShareGiven two binary strings, return their sum (also a binary string).The input strings are bothnon-emptyand contains only characters1or0.Example 1:Input: a = "11", b = "1"Outpu...原创 2020-08-17 14:32:50 · 203 阅读 · 0 评论 -
65. Valid Number
Problem Description:alidate if a given string can be interpreted asa decimal number.Some examples:"0"=>true" 0.1 "=>true"abc"=>false"1 a"=>false"2e10"=>true" -90e3 "=>true" 1e"=>false"e3"=>false" 6e-1"=>...原创 2020-08-17 12:42:44 · 156 阅读 · 0 评论 -
60. Permutation Sequence
Problem Description:The set[1,2,3,...,n]contains a total ofn! unique permutations.By listing and labeling all of the permutations in order, we get the following sequence forn= 3:"123" "132" "213" "231" "312" "321"Givennandk, return the...原创 2020-08-03 17:49:54 · 113 阅读 · 0 评论 -
58. Length of Last Word
Problem Description:Given a stringsconsists of upper/lower-case alphabets and empty space characters' ', return the length of last word (last word means the last appearing word if we loop from left to right) in the string.If the last word does not ...原创 2020-08-03 17:22:25 · 213 阅读 · 0 评论 -
52. N-Queens II
Problem Description:Then-queens puzzle is the problem of placingnqueens on ann×nchessboard such that no two queens attack each other.Given an integern, return the number ofdistinct solutions to then-queens puzzle.Example:Input: 4Output...原创 2020-07-30 16:11:14 · 102 阅读 · 0 评论 -
51. N-Queens
Problem Description:Then-queens puzzle is the problem of placingnqueens on ann×nchessboard such that no two queens attack each other.Given an integern, return all distinct solutions to then-queens puzzle.Each solution contains a distinct bo...原创 2020-07-30 16:03:39 · 149 阅读 · 0 评论 -
50. Pow(x, n)
Problem Description:Implementpow(x,n), which calculatesxraised to the powern(xn).Example 1:Input: 2.00000, 10Output: 1024.00000Example 2:Input: 2.10000, 3Output: 9.26100Example 3:Input: 2.00000, -2Output: 0.25000Explanation: 2...原创 2020-07-29 15:35:14 · 107 阅读 · 0 评论 -
47. Permutations II
Problem Description:Given a collection of numbers that might contain duplicates, return all possible unique permutations.Example:Input: [1,1,2]Output:[ [1,1,2], [1,2,1], [2,1,1]]Code:class Solution { List<List<Integer&原创 2020-07-29 14:25:40 · 105 阅读 · 0 评论 -
46. Permutations
Problem Description:Given a collection ofdistinctintegers, return all possible permutations.Example:Input: [1,2,3]Output:[ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]]Code:class Solution { List<List<Integer..原创 2020-07-29 12:21:28 · 108 阅读 · 0 评论 -
44. Wildcard Matching
Problem Description:Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for'?'and'*'.'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequence).The matching ...原创 2020-07-28 18:16:36 · 173 阅读 · 0 评论 -
SpringBoot JPA MySQL 遇到中文乱码的解决办法
在SpringBoot JPA中使用MySQL时, 数据库的值为中文乱码, 需要如下两个方面的设置,1. 数据库的编码为UTF-8, 或者GB2312 也可以.ALTER SCHEMA `YourDBName` DEFAULT CHARACTER SET utf8 ;2. 更改Springboot的配置文件, 更改MySQL链接如下spring.datasource.url= jdbc:mysql://localhost:3306/YourDBName?characterEnco...原创 2020-06-02 15:52:46 · 714 阅读 · 0 评论 -
700. Search in a Binary Search Tree
Problem Description:Given the root node of a binary search tree (BST) and a value. You need to find the node in the BST that the node's value equals the given value. Return the subtree rooted with that node. If such node doesn't exist, you should return原创 2020-06-01 18:11:00 · 154 阅读 · 0 评论 -
237. Delete Node in a Linked List
Problem:Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Given linked list --head =[4,5,1,9], which looks like following:Exampl...原创 2020-03-26 11:42:07 · 132 阅读 · 0 评论 -
234. Palindrome Linked List
Problem:Given a singly linked list, determine if it is a palindrome.Example 1:Input: 1->2Output: falseExample 2:Input: 1->2->2->1Output: trueFollow up:Could you do it in ...原创 2020-03-24 12:26:14 · 99 阅读 · 0 评论 -
206. Reverse Linked List
Problem:Reverse a singly linked list.Example:Input: 1->2->3->4->5->NULLOutput: 5->4->3->2->1->NULLFollow up:A linked list can be reversed either iteratively...原创 2020-03-24 12:20:29 · 135 阅读 · 0 评论 -
203. Remove Linked List Elements
Problem:Remove all elements from a linked list of integers that have valueval.Example:Input: 1->2->6->3->4->5->6, val = 6Output: 1->2->3->4->5Analysis:本题的...原创 2020-03-24 12:08:04 · 121 阅读 · 0 评论 -
160. Intersection of Two Linked Lists
Problem:Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:begin to intersect at node c1.Example 1:...原创 2020-03-24 11:51:07 · 114 阅读 · 0 评论 -
148. Sort List
Problem:Sort a linked list inO(nlogn) time using constant space complexity.Example 1:Input: 4->2->1->3Output: 1->2->3->4Example 2:Input: -1->5->3->4->0...原创 2020-03-23 18:08:21 · 112 阅读 · 0 评论 -
Java的特点
Java是一种“简单”、面向对象、分布式、解释型、健壮、安全、体系结构中立、可移植、高性能和动态的变成语言。简单:Java的设计目的是让专业程序员觉得既易学又好用。假设你有编程经历,你将不觉得Java难掌握,如果你已经理解面向对象编程的基本概念,学习Java更加容易; 面向对象:面向对象是现代编程语言的重要特征之一,面向对象技术极大地提高了人们的软件开发能力; 分布式:分布式包括数据分布和...原创 2020-03-23 15:24:19 · 618 阅读 · 0 评论 -
Java 概述
一、Java 简介 Java是一种可以撰写跨平台应用程序的面向对象的程序设计语言。Java技术具有卓越的通用性、高效性、平台移植性和安全性,广泛应用于PC,数据中心,游戏控制台、科学超级计算机,移动电话和互联网,同时拥有全球最大的开发者专业社群。 Java是由Sum Microsystems公司推出的Java面向对象程序设计语言(以下简称Java语言)和Java平台的总称。由J...转载 2020-03-23 12:13:25 · 389 阅读 · 0 评论 -
147. Insertion Sort List
Problem:Sort a linked list using insertion sort.A graphical example of insertion sort. The partial sorted list (black) initially contains only the first element in the list.With each iteration ...原创 2020-03-20 18:11:53 · 99 阅读 · 0 评论 -
143. Reorder List
Problem:Given a singly linked listL:L0→L1→…→Ln-1→Ln,reorder it to:L0→Ln→L1→Ln-1→L2→Ln-2→…You maynotmodify the values in the list's nodes, only nodes itself may be changed.Example 1:Giv...原创 2020-03-20 16:29:48 · 91 阅读 · 0 评论 -
142. Linked List Cycle II
Problem:Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull.To represent a cycle in the given linked list, we use an integerposwhich represents the po...原创 2020-03-20 15:34:38 · 85 阅读 · 0 评论 -
141. Linked List Cycle
Problem:Given a linked list, determine if it has a cycle in it.To represent a cycle in the given linked list, we use an integerposwhich represents the position (0-indexed)in the linked list wh...原创 2020-03-20 15:12:42 · 121 阅读 · 0 评论 -
109. Convert Sorted List to Binary Search Tree
Problem: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...原创 2020-03-20 14:58:00 · 130 阅读 · 0 评论 -
92. Reverse Linked List II
Problem:Reverse a linked list from positionmton. Do it in one-pass.Note:1 ≤m≤n≤ length of list.Example:Input: 1->2->3->4->5->NULL, m = 2, n = 4Output: 1->4->3-&...原创 2020-03-19 17:39:29 · 98 阅读 · 0 评论 -
86. Partition List
Problem:Given a linked list and a valuex, partition it such that all nodes less thanxcome before nodes greater than or equal tox.You should preserve the original relative order of the nodes i...原创 2020-03-19 16:27:21 · 129 阅读 · 0 评论 -
83. Remove Duplicates from Sorted List
Problem:Given a sorted linked list, delete all duplicates such that each element appear onlyonce.Example 1:Input: 1->1->2Output: 1->2Example 2:Input: 1->1->2->3->3...原创 2020-03-19 15:29:13 · 80 阅读 · 0 评论 -
82. Remove Duplicates from Sorted List II
Problem:Given a sorted linked list, delete all nodes that have duplicate numbers, leaving onlydistinctnumbers from the original list.Return the linked list sorted as well.Example 1:Input: ...原创 2020-03-19 13:43:26 · 115 阅读 · 0 评论 -
61. Rotate List
Problem:Given a linkedlist, rotate the list to the right bykplaces, wherekis non-negative.Example 1:Input: 1->2->3->4->5->NULL, k = 2Output: 4->5->1->2->3->...原创 2020-03-19 12:24:08 · 102 阅读 · 0 评论 -
274. H-Index
Problem:Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher's h-index.According to thedefinition of h-index on Wikip...原创 2020-03-16 16:53:39 · 98 阅读 · 0 评论 -
205. Isomorphic Strings
Problem:Given two stringssandt, determine if they are isomorphic.Two strings are isomorphic if the characters inscan be replaced to gett.All occurrences of a character must be replaced wi...原创 2020-03-16 16:33:17 · 108 阅读 · 0 评论 -
242. Valid Anagram
Problem:Given two stringssandt, write a function to determine iftis an anagram ofs.Example 1:Input: s = "anagram", t = "nagaram"Output: trueExample 2:Input: s = "rat", t = "car"...原创 2020-03-14 16:48:19 · 85 阅读 · 0 评论 -
204. Count Primes
Problem:Count the number of prime numbers less than a non-negative number,n.Example:Input: 10Output: 4Explanation: There are 4 prime numbers less than 10, they are 2, 3, 5, 7.Analysis:...原创 2020-03-13 16:15:17 · 118 阅读 · 0 评论 -
202. Happy Number
Problem: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 th...原创 2020-03-11 15:45:23 · 144 阅读 · 0 评论 -
187. Repeated DNA Sequences
Problem:All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the ...原创 2020-03-11 15:08:20 · 127 阅读 · 0 评论 -
166. Fraction to Recurring Decimal
Problem:Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.If the fractional part is repeating, enclose the repeating part in parent...原创 2020-03-11 13:03:16 · 121 阅读 · 0 评论 -
149. Max Points on a Line
Problem:Givennpoints on a 2D plane, find the maximum number of points that lie on the same straight line.Example 1:Input: [[1,1],[2,2],[3,3]]Output: 3Explanation:^|| o| o| ...原创 2020-03-10 15:40:28 · 102 阅读 · 0 评论 -
138. Copy List with Random Pointer
Problem: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 adeep copyof the list.The Linked List is repr...原创 2020-03-04 13:34:55 · 137 阅读 · 0 评论