📣 Back to School开学季 - VIP通行证5折优惠!蓝莓、Offer多多同步优惠
楼主: ttgao
跳转到指定楼层
上一主题 下一主题
收起左侧

立贴!从今天开始刷题。

🔗
 楼主| ttgao 2019-5-15 13:19:32 | 只看该作者
全局:
此题就是两个遍历,从J里面取出一个字符然后在stone里面遍历一边。
回复

使用道具 举报

🔗
 楼主| ttgao 2019-5-15 13:44:20 | 只看该作者
全局:
204. Count Primes

Count the number of prime numbers less than a non-negative number, n.

Example:

Input: 10
Output: 4
Explanation: There are 4 prime numbers less than 10, they are 2, 3, 5, 7.

回复

使用道具 举报

🔗
 楼主| ttgao 2019-5-15 13:45:01 | 只看该作者
全局:
求质数的个数,其实就是判断一个数是否是质数。我的方法不够好。不知道有啥好的办法。
回复

使用道具 举报

🔗
 楼主| ttgao 2019-5-15 14:45:02 | 只看该作者
全局:
242. Valid Anagram

Given two strings s and t , write a function to determine if t is an anagram of s.

Example 1:

Input: s = "anagram", t = "nagaram"
Output: true

Example 2:

Input: s = "rat", t = "car"
Output: false

Note:
You may assume the string contains only lowercase alphabets.

Follow up:
What if the inputs contain unicode characters? How would you adapt your solution to such case?
回复

使用道具 举报

🔗
 楼主| ttgao 2019-5-15 14:46:29 | 只看该作者
全局:
此题和387有点类似,用一个arr[s.charAt(i)-'a']来访问index i的字符,然后一个加,一个减,最后看是否等于零。等于零就是表示是相同数量的某字母。
回复

使用道具 举报

🔗
 楼主| ttgao 2019-5-16 01:20:32 | 只看该作者
全局:
8. String to Integer (atoi)

Implement atoi which converts a string to an integer.

The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes an optional initial plus or minus sign followed by as many numerical digits as possible, and interprets them as a numerical value.

The string can contain additional characters after those that form the integral number, which are ignored and have no effect on the behavior of this function.

If the first sequence of non-whitespace characters in str is not a valid integral number, or if no such sequence exists because either str is empty or it contains only whitespace characters, no conversion is performed.

If no valid conversion could be performed, a zero value is returned.

Note:

    Only the space character ' ' is considered as whitespace character.
    Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231,  231 − 1]. If the numerical value is out of the range of representable values, INT_MAX (231 − 1) or INT_MIN (−231) is returned.

Example 1:

Input: "42"
Output: 42

Example 2:

Input: "   -42"
Output: -42
Explanation: The first non-whitespace character is '-', which is the minus sign.
             Then take as many numerical digits as possible, which gets 42.

Example 3:

Input: "4193 with words"
Output: 4193
Explanation: Conversion stops at digit '3' as the next character is not a numerical digit.

Example 4:

Input: "words and 987"
Output: 0
Explanation: The first non-whitespace character is 'w', which is not a numerical
             digit or a +/- sign. Therefore no valid conversion could be performed.

Example 5:

Input: "-91283472332"
Output: -2147483648
Explanation: The number "-91283472332" is out of the range of a 32-bit signed integer.
             Thefore INT_MIN (−231) is returned.

回复

使用道具 举报

🔗
 楼主| ttgao 2019-5-16 01:21:13 | 只看该作者
全局:
此题我感觉很有难度。要考虑的情况太多,代码量会非常大。
回复

使用道具 举报

🔗
 楼主| ttgao 2019-5-16 12:09:09 | 只看该作者
全局:
535. Encode and Decode TinyURL

TinyURL is a URL shortening service where you enter a URL such as https://leetcode.com/problems/design-tinyurl and it returns a short URL such as http://tinyurl.com/4e9iAk.

Design the encode and decode methods for the TinyURL service. There is no restriction on how your encode/decode algorithm should work. You just need to ensure that a URL can be encoded to a tiny URL and the tiny URL can be decoded to the original URL.
回复

使用道具 举报

🔗
 楼主| ttgao 2019-5-16 12:11:24 | 只看该作者
全局:
此题是一道design题目,其实就是如何将很长的string按一定比例换算成较短的string。

我觉得方法很多,可以考虑纯数字的办法,把10进制转成62进制。(这样string马上就短了很多了)。

回复

使用道具 举报

🔗
 楼主| ttgao 2019-5-16 14:43:05 | 只看该作者
全局:
146. LRU Cache

Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put.

get(key) - Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1.
put(key, value) - Set or insert the value if the key is not already present. When the cache reached its capacity, it should invalidate the least recently used item before inserting a new item.

Follow up:
Could you do both operations in O(1) time complexity?

Example:

LRUCache cache = new LRUCache( 2 /* capacity */ );

cache.put(1, 1);
cache.put(2, 2);
cache.get(1);       // returns 1
cache.put(3, 3);    // evicts key 2
cache.get(2);       // returns -1 (not found)
cache.put(4, 4);    // evicts key 1
cache.get(1);       // returns -1 (not found)
cache.get(3);       // returns 3
cache.get(4);       // returns 4
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表