Daily brushing title 191117

  A slag slag Bloggers, brush leetcode Chou Chou himself, the great God who made better way to look to the wing. Title and solution from power button (LeetCode), Portal .

algorithm:

  topic:

  Gives a 32-bit signed integer, you need this integer number on each inverted.

  Example 1:

  Input: 123
  Output: 321
   Example 2:

  Input: -123
  Output: -321
  Example 3:

  Input: 120
  Output: 21
  Note:

  Suppose we have an environment can only store a 32-bit signed integer, then the value range of [-231 231--1]. Please According to this hypothesis, if integer overflow after reverse it returns 0.

solution:

public class Solution {
    public int Reverse(int x) {

        long temp = 0;

        while(x !=0 )
        {
            var pop = x % 10;
            temp = temp * 10 + pop;

            if(temp > int.MaxValue || temp < int.MinValue)
            {
                return 0;
            }

            x = x/10;
        }

        return (int)temp;
    }
}

  The official solution, the portal . Actually, the key lies in two things, one is to build a similar "stack" of the structure, the second is to determine whether overflow. Official to determine whether the solution overflow bit mean, the other can just use int to deal with. The above solution is actually borrowed long, a little too good.

 

database: 

Employee table contains all employees, their managers belong to employees. Each employee has a Id, in addition to a correspondence Id manager of staff.

---- + ------- + -------- + + ----------- +
| Id | the Name | the Salary | ManagerId |
+ ---- + ----------- -------- + + + -------
|. 1 | Joe | 70000 |. 3 |
| 2 | Henry | 80000 |. 4 |
|. 3 | SAM | 60000 | NULL |
| 4 | Max | 90000 | NULL |
+ ---- + ------- + -------- + ----------- +
given the employee table, write a SQL query that you can get the names of managers earning more than their employees. In the above table, Joe is the only one earning more than his manager's staff.

+----------+
| Employee |
+----------+
| Joe |
+----------+

 

solution:

SELECT 
e.NAME as Employee
FROM Employee e
left join Employee m on e.ManagerId = m.Id 
WHERE e.Salary > m.Salary

  

  The official answer, Portal .

 

  Two simple little title, but be regarded as a fresh start, two dogs to stick ah.

  

Guess you like

Origin www.cnblogs.com/dogtwo0214/p/11875840.html