算法每日题
QJB25
这个作者很懒,什么都没留下…
展开
-
Next Greater Element(下一个更大的元素)
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 nums原创 2017-02-27 22:18:49 · 366 阅读 · 0 评论 -
c++中vector的用法详解
vector是C++标准模板库中的部分内容,它是一个多功能的,能够操作多种数据结构和算法的模板类和函数库。vector是一个容器,它能够存放各种类型的对象,简单地说,vector是一个能够存放任意类型的动态数组,可以动态改变大小。 用法:1.为了使用vector,必须在你的头文件中包含下面的代码: #include 2.vector属于std命名域的,因此需要通转载 2017-02-27 22:09:00 · 240 阅读 · 0 评论 -
566. Reshape the Matrix
In MATLAB, there is a very useful function called ‘reshape’, which can reshape a matrix into a new one with different size but keep its original data.You’re given a matrix represented by a two-dimensio原创 2017-05-12 23:27:40 · 418 阅读 · 0 评论 -
575. Distribute Candies 以及 unordered_map<int, int>函数以及map<int, int>函数
Given an integer array with even length, where different numbers in this array represent different kinds of candies. Each number means one candy of the corresponding kind. You need to distribute these原创 2017-05-11 18:22:22 · 337 阅读 · 0 评论 -
389. Find the Difference
Given two strings s and t which consist of only lowercase letters.String t is generated by random shuffling string s and then add one more letter at a random position.Find the letter that was added in原创 2017-04-05 21:06:54 · 214 阅读 · 0 评论 -
448. Find All Numbers Disappeared in an Array and sort()函数的简单用法
Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements of [1, n] inclusive that do not appear in this array.原创 2017-03-06 22:42:44 · 295 阅读 · 0 评论 -
136. Single Number and与、或、异或、取反、左移和右移运算
Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using ext原创 2017-03-06 20:41:08 · 218 阅读 · 0 评论 -
Keyboard Row
Given a List of words, return the words that can be typed using letters of alphabet on only one row's of American keyboard like the image below.Example 1:Input: ["Hello", "Alaska", "Da转载 2017-02-26 16:32:19 · 313 阅读 · 0 评论 -
算法每日题Hamming distance
1.The Hamming distance between two integers is the number of positions at which the corresponding bits are different.Given two integers x and y, calculate the Hamming distance(汉明距离).No原创 2017-02-20 22:49:48 · 365 阅读 · 0 评论 -
Number Complement(数量补语)
Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation.Note:The given integer is guaranteed to fit within the range原创 2017-02-21 23:15:15 · 441 阅读 · 0 评论 -
104. Maximum Depth of Binary Tree以及->的一些小用法解释
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.my answer:/** * Definition原创 2017-03-08 12:25:26 · 242 阅读 · 0 评论 -
520. Detect Capital
Given a word, you need to judge whether the usage of capitals in it is right or not.We define the usage of capitals in a word to be right when one of the following cases holds:All letters in t原创 2017-03-02 21:13:45 · 191 阅读 · 0 评论 -
292. Nim Game
You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will be the原创 2017-03-02 20:36:40 · 217 阅读 · 0 评论 -
485. Max Consecutive Ones
Given a binary array, find the maximum number of consecutive 1s in this array.Example 1:Input: [1,1,0,1,1,1]Output: 3Explanation: The first two digits or the last three digits are consecutiv原创 2017-03-01 22:21:18 · 207 阅读 · 0 评论 -
463. Island Perimeter
You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is completely原创 2017-02-28 21:40:16 · 223 阅读 · 0 评论 -
344. Reverse String
Write a function that takes a string as input and returns the string reversed.Example:Given s = "hello", return "olleh".my answer:class Solution {public: string reverseString(st原创 2017-02-28 18:14:31 · 227 阅读 · 0 评论 -
412. Fizz Buzz
Write a program that outputs the string representation of numbers from 1 to n.But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”.原创 2017-02-28 17:39:58 · 196 阅读 · 0 评论 -
LeetCode 561. Array Partition I
Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), …, (an, bn) which makes sum of min(ai, bi) for all i from 1 to n as large as possibl原创 2017-05-09 19:53:18 · 615 阅读 · 0 评论