LeetCode #15 (#171、#172、#175)

172. Factorial Trailing Zeroes

Given an integer n, return the number of trailing zeroes in n!.

Example 1:

Input: 3
Output: 0
Explanation: 3! = 6, no trailing zero.

Example 2:

Input: 5
Output: 1
Explanation: 5! = 120, one trailing zero.

Note: Your solution should be in logarithmic time complexity.

//Solution
int trailingZeroes(int n){
    int c = n / 5;
    while( n /= 5 ) c += n / 5;
    return c; 
}
171. Excel Sheet Column Number

Given a column title as appear in an Excel sheet, return its corresponding column number.

For example:

   A -> 1
   B -> 2
   C -> 3
   ...
   Z -> 26
   AA -> 27
   AB -> 28 
   ...

Example 1:

Input: "A"
Output: 1

Example 2:

Input: "AB"
Output: 28

Example 3:

Input: "ZY"
Output: 701
//Solution
class Solution {
public:
    int titleToNumber(string s) {
        int ret=0;
        for(int i=0;i<s.size();i++)
        {
            ret*=26;
            ret+=s[i]-'A'+1;
        }
        return ret;
    }
};
175. Combine Two Tables
/*SQL Schema*/
Create table Person (PersonId int, FirstName varchar(255), LastName varchar(255))

Create table Address (AddressId int, PersonId int, City varchar(255), State varchar(255))

Truncate table Person

insert into Person (PersonId, LastName, FirstName) values ('1', 'Wang', 'Allen')

Truncate table Address

insert into Address (AddressId, PersonId, City, State) values ('1', '2', 'New York City', 'New York')

Table: Person

+-------------+---------+
| Column Name | Type    |
+-------------+---------+
| PersonId    | int     |
| FirstName   | varchar |
| LastName    | varchar |
+-------------+---------+
PersonId is the primary key column for this table.

Table: Address

+-------------+---------+
| Column Name | Type    |
+-------------+---------+
| AddressId   | int     |
| PersonId    | int     |
| City        | varchar |
| State       | varchar |
+-------------+---------+
AddressId is the primary key column for this table.

Write a SQL query for a report that provides the following information for each person in the Person table, regardless if there is an address for each of those people:

FirstName, LastName, City, State
-- Solution
# Write your MySQL query statement below
select FirstName, LastName, City, State 
from Person left join Address on Person.PersonId = Address.PersonId;
发布了77 篇原创文章 · 获赞 12 · 访问量 6745

猜你喜欢

转载自blog.csdn.net/weixin_44198992/article/details/105572066