service和serviceImpl的选择

service和serviceImpl的选择

有些同行公司代码风格使用service层=service接口+serviceImpl实现类;

而有的同行公司的代码风格是service层=service类;

网上有人说是因为当项目的业务逻辑简单时,可选择service层=service类;

当项目的业务复杂时,可选择service层=service接口+serviceImpl实现类;

至于复杂和简单的度得自己把握;

今天在看 spring实战(第4版)的时候,看到解释

如下:

spring鼓励应用程序的各个层以接口的形式暴露功能,在service层,可以使用service接口+serviceImple实现类,也可以使用service类,但考虑到“接口时实现松耦合的关键”,所以更加推荐使用

service接口+serviceImple实现类的方式来写service层代码。

核心是“松耦合”。

leetcode-3-longest-substring-without-repeating-characters

Description

Given a string, find the length of the longest substring without repeating characters.

Example 1:

1
2
3
Input: "abcabcbb"
Output: 3
Explanation: The answer is "abc", with the length of 3.

Example 2:

1
2
3
Input: "bbbbb"
Output: 1
Explanation: The answer is "b", with the length of 1.

Example 3:

1
2
3
4
Input: "pwwkew"
Output: 3
Explanation: The answer is "wke", with the length of 3.
Note that the answer must be a substring, "pwke" is a subsequence and not a substring.

leetcode-4-median-of-two-sorted-arrays

Description

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 nums2 cannot be both empty.

Example 1:

1
2
3
4
nums1 = [1, 3]
nums2 = [2]

The median is 2.0

Example 2:

1
2
3
4
nums1 = [1, 2]
nums2 = [3, 4]

The median is (2 + 3)/2 = 2.5

leetcode-2-add-two-numbers

Description

You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.

You may assume the two numbers do not contain any leading zero, except the number 0 itself.

Example:

1
2
3
Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
Output: 7 -> 0 -> 8
Explanation: 342 + 465 = 807.

leetcode-24-swap-nodes-in-pairs

Description

Given a linked list, swap every two adjacent nodes and return its head.

Example:

1
Given 1->2->3->4, you should return the list as 2->1->4->3.

Note:

  • Your algorithm should use only constant extra space.
  • You may not modify the values in the list’s nodes, only nodes itself may be changed.

leetcode-844-backspace-string-compare

Description

Given two strings S and T, return if they are equal when both are typed into empty text editors. #means a backspace character.

Example 1:

1
2
3
Input: S = "ab#c", T = "ad#c"
Output: true
Explanation: Both S and T become "ac".

Example 2:

1
2
3
Input: S = "ab##", T = "c#d#"
Output: true
Explanation: Both S and T become "".

Example 3:

1
2
3
Input: S = "a##c", T = "#a#c"
Output: true
Explanation: Both S and T become "c".

Example 4:

1
2
3
Input: S = "a#c", T = "b"
Output: false
Explanation: S becomes "c" while T becomes "b".

Note:

  1. 1 <= S.length <= 200
  2. 1 <= T.length <= 200
  3. S and T only contain lowercase letters and '#' characters.

Follow up:

  • Can you solve it in O(N) time and O(1)space?

leetcode-20-valid-parentheses

Description

Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.

An input string is valid if:

  1. Open brackets must be closed by the same type of brackets.
  2. Open brackets must be closed in the correct order.

Note that an empty string is also considered valid.

Example 1:

1
2
Input: "()"
Output: true

Example 2:

1
2
Input: "()[]{}"
Output: true

Example 3:

1
2
Input: "(]"
Output: false

Example 4:

1
2
Input: "([)]"
Output: false

Example 5:

1
2
Input: "{[]}"
Output: true

leetcode-682-baseball-game

Description

You’re now a baseball game point recorder.

Given a list of strings, each string can be one of the 4 following types:

  1. Integer (one round’s score): Directly represents the number of points you get in this round.
  2. "+" (one round’s score): Represents that the points you get in this round are the sum of the last two valid round’s points.
  3. "D" (one round’s score): Represents that the points you get in this round are the doubled data of the last valid round’s points.
  4. "C" (an operation, which isn’t a round’s score): Represents the last valid round’s points you get were invalid and should be removed.

Each round’s operation is permanent and could have an impact on the round before and the round after.

You need to return the sum of the points you could get in all the rounds.

Example 1:

1
2
3
4
5
6
7
8
Input: ["5","2","C","D","+"]
Output: 30
Explanation:
Round 1: You could get 5 points. The sum is: 5.
Round 2: You could get 2 points. The sum is: 7.
Operation 1: The round 2's data was invalid. The sum is: 5.
Round 3: You could get 10 points (the round 2's data has been removed). The sum is: 15.
Round 4: You could get 5 + 10 = 15 points. The sum is: 30.

Example 2:

1
2
3
4
5
6
7
8
9
10
11
Input: ["5","-2","4","C","D","9","+","+"]
Output: 27
Explanation:
Round 1: You could get 5 points. The sum is: 5.
Round 2: You could get -2 points. The sum is: 3.
Round 3: You could get 4 points. The sum is: 7.
Operation 1: The round 3's data is invalid. The sum is: 3.
Round 4: You could get -4 points (the round 3's data has been removed). The sum is: -1.
Round 5: You could get 9 points. The sum is: 8.
Round 6: You could get -4 + 9 = 5 points. The sum is 13.
Round 7: You could get 9 + 5 = 14 points. The sum is 27.

Note:

The size of the input list will be between 1 and 1000.

Every integer represented in the list will be between -30000 and 30000.

leetcode-225-implement-stacks-using-queue

Description

  • Implement the following operations of a stack using queues.

    • push(x) – Push element x onto stack.
    • pop() – Removes the element on top of the stack.
    • top() – Get the top element.
    • empty() – Return whether the stack is empty.

    Example:

    1
    2
    3
    4
    5
    6
    7
    MyStack stack = new MyStack();

    stack.push(1);
    stack.push(2);
    stack.top(); // returns 2
    stack.pop(); // returns 2
    stack.empty(); // returns false

    Notes:

    • You must use only standard operations of a queue – which means only push to back, peek/pop from front, size, and is empty operations are valid.
    • Depending on your language, queue may not be supported natively. You may simulate a queue by using a list or deque (double-ended queue), as long as you use only standard operations of a queue.
    • You may assume that all operations are valid (for example, no pop or top operations will be called on an empty stack).

leetcode-496-next-greater-element-i

Description

  1. You are given two arrays (without duplicates)nums1 and nums2 where nums1’s elements are subset of nums2. Find all the next greater numbers for nums1‘s elements in the corresponding places of nums2.

    The Next Greater Number of a number x in nums1 is the first greater number to its right in nums2. If it does not exist, output -1 for this number.

    Example 1:

    1
    2
    3
    4
    5
    6
    Input: nums1 = [4,1,2], nums2 = [1,3,4,2].
    Output: [-1,3,-1]
    Explanation:
    For number 4 in the first array, you cannot find the next greater number for it in the second array, so output -1.
    For number 1 in the first array, the next greater number for it in the second array is 3.
    For number 2 in the first array, there is no next greater number for it in the second array, so output -1.
**Example 2:**

1
2
3
4
5
Input: nums1 = [2,4], nums2 = [1,2,3,4].
Output: [3,-1]
Explanation:
For number 2 in the first array, the next greater number for it in the second array is 3.
For number 4 in the first array, there is no next greater number for it in the second array, so output -1.
**Note:** 1. All elements in `nums1` and `nums2` are unique. 2. The length of both `nums1` and `nums2` would not exceed 1000.
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×