题目 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. 题意 给你一个字符串,找…

2018年2月26日 0条评论 0点热度 阅读全文

题目 Given two arrays, write a function to compute their intersection. Example: Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2, 2]. Note: Each element in the result should appear as many times as it shows in both arrays. The result can be in any order. 题意…

2018年2月26日 0条评论 0点热度 阅读全文

题目 Given two arrays, write a function to compute their intersection. Example: Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2]. Note: Each element in the result must be unique. The result can be in any order. 题意 两数组的交集 题解 遍历nums1中的元素nums1[i],判断nums1[i]是否…

2018年2月25日 0条评论 0点热度 阅读全文

题目 Given two strings s and t, write a function to determine if t is an anagram of s. s = "anagram", t = "nagaram", return true. s = "rat", t = "car", return false. 题意 判断 t 是否是由 s 颠倒顺序构成的。 题解 对s和t都进行排序,之后判断s==t ? C++代码 C++中string排序的用法为sort(s.begin(), s.end()); …

2018年2月25日 0条评论 0点热度 阅读全文

题目 You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? Note: Given n will be a positive integer. Example 1: Input: 2 Output: 2 Explanation: There …

2018年2月24日 0条评论 0点热度 阅读全文

题目 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 firs…

2018年2月23日 0条评论 0点热度 阅读全文

题目 Implement the following operations of a queue using stacks. push(x) -- Push element x to the back of queue. pop() -- Removes the element from in front of queue. peek() -- Get the front element. empty() -- Return whether the queue is empty. Notes: You must u…

2018年2月23日 0条评论 0点热度 阅读全文

题目 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. Notes: You must use only standard ope…

2018年2月21日 0条评论 0点热度 阅读全文

题目 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 …

2018年2月21日 0条评论 0点热度 阅读全文

题目 Given a 2D integer matrix M representing the gray scale of an image, you need to design a smoother to make the gray scale of each cell becomes the average gray scale (rounding down) of all the 8 surrounding cells and itself. If a cell has less than 8 surrou…

2018年2月19日 0条评论 0点热度 阅读全文