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

立贴!从今天开始刷题。

全局:
向楼主学习
回复

使用道具 举报

🔗
shwanfan 2019-5-13 12:45:59 | 只看该作者
本楼:
全局:
2 sum, map ;)
回复

使用道具 举报

🔗
 楼主| ttgao 2019-5-14 11:18:21 | 只看该作者
全局:
20. Valid Parentheses

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

An input string is valid if:

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

Note that an empty string is also considered valid.

Example 1:

Input: "()"
Output: true

Example 2:

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

Example 3:

Input: "(]"
Output: false

Example 4:

Input: "([)]"
Output: false

Example 5:

Input: "{[]}"
Output: true

回复

使用道具 举报

🔗
 楼主| ttgao 2019-5-14 11:19:38 | 只看该作者
全局:
此题用stack的办法,把对应的符号一个一个压进去。如果pop出的符号是相对应的符号而且stack为空,那就返回true。
回复

使用道具 举报

🔗
 楼主| ttgao 2019-5-14 12:01:16 | 只看该作者
全局:
155. Min Stack

Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.

    push(x) -- Push element x onto stack.
    pop() -- Removes the element on top of the stack.
    top() -- Get the top element.
    getMin() -- Retrieve the minimum element in the stack.

Example:

MinStack minStack = new MinStack();
minStack.push(-2);
minStack.push(0);
minStack.push(-3);
minStack.getMin();   --> Returns -3.
minStack.pop();
minStack.top();      --> Returns 0.
minStack.getMin();   --> Returns -2.
回复

使用道具 举报

🔗
 楼主| ttgao 2019-5-14 12:03:46 | 只看该作者
全局:
此题建2个stack一个存数据,另外一个存最小的数。然后和压进来的数字比较,如果比较小就作为新数压进来,否则就压老的最小的数字进站。
回复

使用道具 举报

🔗
 楼主| ttgao 2019-5-14 20:05:54 | 只看该作者
全局:
此题建2个stack一个存数据,另外一个存最小的数。然后和压进来的数字比较,如果比较小就作为新数压进来,否则就压老的最小的数字进站。
回复

使用道具 举报

🔗
 楼主| ttgao 2019-5-15 13:06:54 | 只看该作者
全局:
387. First Unique Character in a String

Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1.

Examples:

s = "leetcode"
return 0.

s = "loveleetcode",
return 2.

Note: You may assume the string contain only lowercase letters.
回复

使用道具 举报

🔗
 楼主| ttgao 2019-5-15 13:10:33 | 只看该作者
全局:
此题不难,但是有一个取巧的办法,建一个26个字母的数组。然后用arr[s.charAt(i)-'a']来访问index i的字符。

这样遍历一次就可以统计出哪个字母重复过了。
回复

使用道具 举报

🔗
 楼主| ttgao 2019-5-15 13:18:47 | 只看该作者
全局:
771. Jewels and Stones

You're given strings J representing the types of stones that are jewels, and S representing the stones you have.  Each character in S is a type of stone you have.  You want to know how many of the stones you have are also jewels.

The letters in J are guaranteed distinct, and all characters in J and S are letters. Letters are case sensitive, so "a" is considered a different type of stone from "A".

Example 1:

Input: J = "aA", S = "aAAbbbb"
Output: 3

Example 2:

Input: J = "z", S = "ZZ"
Output: 0

Note:

    S and J will consist of letters and have length at most 50.
    The characters in J are distinct.

回复

使用道具 举报

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

本版积分规则

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