1.Algorithm
https://leetcode-cn.com/problems/merge-two-sorted-lists/
Method 1: Recursive
idea
We can recursively define the following two lists in the merge
operation (ignoring border situations, such as empty list, etc.):
\left\{ \begin{array}{ll} list1[0] + merge(list1[1:], list2) & list1[0] < list2[0] \\ list2[0] + merge(list1, list2[1:]) & otherwise \end{array} \right.{list1[0]+merge(list1[1:],list2)list2[0]+merge(list1,list2[1:])list1[0]<list2[0]otherwise
In other words, two lists with the rest of the head of a smaller element of merge
the operating results of the merger.
We directly above recursive algorithm process modeling, first consider the boundary conditions. Special, if l1
or l2
beginning null
, so there is no need to merge operations, so we only need to return a non-empty list. Otherwise, we have to determine l1
and l2
which elements of the head is smaller, then recursively down a decision in the value added to the result. If the two lists are empty, then the process terminates, so recursive process will eventually terminate.
class Solution { public ListNode mergeTwoLists(ListNode l1, ListNode l2) { if (l1 == null) { return l2; } else if (l2 == null) { return l1; } else if (l1.val < l2.val) { l1.next = mergeTwoLists(l1.next, l2); return l1; } else { l2.next = mergeTwoLists (L1, l2.next); return l2; } } }
2.Review
https://link.medium.com/qNt4XAqc0W
3.Tips
@PostMapping("/multiUpload") @ResponseBody public String multiUpload(HttpServletRequest request) { List<MultipartFile> files = ((MultipartHttpServletRequest) request).getFiles("file"); String filePath = "/Users/itinypocket/workspace/temp/"; for (int i = 0; i < files.size(); i++) { MultipartFile file = files.get(i); if (file.isEmpty()) { return "Uploading" + (i ++) + "files failed"; } String fileName = file.getOriginalFilename(); File dest = new File(filePath + fileName); try { file.transferTo (); LOGGER.info ( "first" + (i + 1) + "files uploaded successfully"); } catch (IOException e) { LOGGER.error(e.toString(), e); return "Uploading" + (i ++) + "files failed"; } } return "Upload successful"; }
4.Share
https://www.cnblogs.com/tanshaoshenghao/p/10924205.html
Javah constant pool data to frequently used into the memory to avoid repetition of creation and destruction, data sharing, improve system performance.
From jdk1.7, the string constant pool is implemented in the Java heap memory
String s1 = "hello"; String s2 = new String("hello");
s1 is to go find the constant pool, if not back into the constant pool in the new, s2 direct new without the constant pool.
String s1 = new String("hello ") + new String("world");
Now the heap create two objects, spliced using stringBuilder, and then generate a new object variable s1 point to the new object "hello world".
s1.intern ();
This is to query whether the string constant pool if there is no direct return, the variable is registered in the constant pool, and back again.
String s1 = "hello "; String s2 = "world"; String s3 = s1 + s2; String s4 = "hello world"; System.out.println(s3 == s4);
s3 is an object with the new splicing stringbuilder so s3! = s4