自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(34)
  • 收藏
  • 关注

原创 LEETCODE--Linked List Cycle

Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using extra space? /** * Definition for singly-linked list. * struct ListNode { * int val; *

2017-02-28 11:52:12 218

原创 LEETCODE-- Arranging Coins

You have a total of n coins that you want to form in a staircase shape, where every k-th row must have exactly k coins. Given n, find the total number of full staircase rows that can be formed. n is

2017-02-20 17:12:34 207

原创 LEETCODE--Number of Segments in a String

Count the number of segments in a string, where a segment is defined to be a contiguous sequence of non-space characters. Please note that the string does not contain any non-printable characters. Ex

2017-02-20 15:49:50 186

原创 LEETCODE--Reverse Vowels of a String

Write a function that takes a string as input and reverse only the vowels of a string. Example 1: Given s = “hello”, return “holle”. Example 2: Given s = “leetcode”, return “leotcede”. Note: Th

2017-02-20 10:55:59 304

原创 LEETCODE--Valid Perfect Square

Given a positive integer num, write a function which returns True if num is a perfect square else False. Note: Do not use any built-in library function such as sqrt. Example 1: Input: 16 Returns:

2017-02-20 09:55:20 170

原创 LEETCODE-- Power of Four

Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Example: Given num = 16, return true. Given num = 5, return false. Follow up: Could you solve it without lo

2017-02-20 09:53:26 340

原创 Bit Manipulantion 技巧

power of two 条件:!num & (num - 1)可以用来判断一个数是否为2的次方数 power of four 条件:(power of 2)&&(4的次方数,减1之后可以被3整除)

2017-02-20 08:35:47 209

原创 LEETCODE--Path Sum III

You are given a binary tree in which each node contains an integer value. Find the number of paths that sum to a given value. The path does not need to start or end at the root or a leaf, but it must

2017-02-15 13:00:58 191

原创 Relative Ranks

Given scores of N athletes, find their relative ranks and the people with the top three highest scores, who will be awarded medals: “Gold Medal”, “Silver Medal” and “Bronze Medal”. Example 1: Input:

2017-02-15 10:45:02 402

原创 C++中 vector可使用的函数和使用方式

//vec1为已经存在并赋值了的容器;vector< int> vec2(vec1);//将vec1赋值给vec2 (vec2 = vec1) sort(vec1.begin(), vec.begin());//升序排列reverse(vec1.begin(), vec.begin());//容器中各元素位置反转

2017-02-15 10:42:59 404

原创 LEETCODE--Next Greater Element I

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.

2017-02-14 17:54:09 250

原创 LEETCODE--Base 7

Given an integer, return its base 7 string representation. Example 1: Input: 100 Output: “202”Example 2: Input: -7 Output: “-10”Note: The input will be in range of [-1e7, 1e7]. class Solution {pu

2017-02-14 17:00:17 245

原创 LEETCODE--Repeated Substring Pattern

Given a non-empty string check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. You may assume the given string consists of lowercase Englis

2017-02-12 14:22:23 247

原创 LEETCODE--Maximum Subarray

Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example, given the array [-2,1,-3,4,-1,2,1,-5,4], the contiguous subarray [4,-1,2,1] has

2017-02-09 19:01:11 198

原创 LEETCODE--Search Insert Position

Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You may assume no duplicates in the array. H

2017-02-09 18:48:23 223

原创 LEETCODE--Add Strings

Given two non-negative integers num1 and num2 represented as string, return the sum of num1 and num2. Note: The length of both num1 and num2 is < 5100. Both num1 and num2 contains only digits 0-9.

2017-02-08 18:07:17 196

原创 标准C++中的string类的用法总结

转自标准C++中的string类的用法总结相信使用过MFC编程的朋友对CString这个类的印象应该非常深刻吧?的确,MFC中的CString类使用起来真的非常的方便好用。但是如果离开了MFC框架,还有没有这样使用起来非常方便的类呢?答案是肯定的。也许有人会说,即使不用MFC框架,也可以想办法使用MFC中的API,具体的操作方法在本文最后给出操作方法。其实,可能很多人很可能会忽略掉标准C++中str

2017-02-08 11:56:46 330

原创 LEETCODE--Number of Boomerangs

Given n points in the plane that are all pairwise distinct, a “boomerang” is a tuple of points (i, j, k) such that the distance between i and j equals the distance between i and k (the order of the tup

2017-02-06 20:58:49 186

原创 C++ map的遍历

map<long,int> group;for(auto& p : group){ cout << p.second << endl}

2017-02-06 20:57:39 1186

原创 LEETCODE--Intersection of Two Arrays II

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

2017-02-06 13:46:29 386

转载 C++ map的基本操作和使用

转自C++ map的基本操作和使用 1、map简介map是一类关联式容器。它的特点是增加和删除节点对迭代器的影响很小,除了那个操作节点,对其他的节点都没有什么影响。对于迭代器来说,可以修改实值,而不能修改key。2、map的功能自动建立Key - value的对应。key 和 value可以是任意你需要的类型。 根据key值快速查找记录,查找的复杂度基本是Log(N),如果有1000个记录,

2017-02-06 13:31:41 251

原创 LEETCODE--Missing Number

Given an array containing n distinct numbers taken from 0, 1, 2, …, n, find the one that is missing from the array. For example, Given nums = [0, 1, 3] return 2. Note: Your algorithm should run i

2017-02-06 12:58:30 161

原创 LEETCODE--Longest Palindrome

Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters. This is case sensitive, for example “Aa” is not consid

2017-02-05 18:31:20 150

原创 LEETCODE--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

2017-02-05 18:09:21 161

原创 LEETCODE--Best Time to Buy and Sell Stock II

Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one a

2017-02-04 22:33:28 169

原创 LEETCODE--Sum of Left Leaves

Find the sum of all left leaves in a given binary tree. Example: 3 / \ 9 20 / \ 15 7There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24

2017-02-04 21:45:29 153

原创 LEETCODE--Intersection of Two Arrays

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

2017-02-04 17:18:37 162

原创 LEETCODE--Ransom Note

Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the ransom note can be constructed from the magazines ; oth

2017-02-03 17:47:22 161

原创 LEETCODE--Minimum Moves to Equal Array Elements

Given a non-empty integer array of size n, find the minimum number of moves required to make all array elements equal, where a move is incrementing n - 1 elements by 1. Example: Input: [1,2,3]Outpu

2017-02-03 11:32:48 155

原创 LEETCODE--Assign Cookies

Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a greed factor gi, which is the minimum size of a cook

2017-02-03 10:40:44 253

原创 LEETCODE--Two Sum II - Input array is sorted

Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbers s

2017-02-01 17:40:35 222

原创 LEETCODE--Construct the Rectangle

For a web developer, it is very important to know how to design a web page’s size. So, given a specific rectangular web page’s area, your job by now is to design a rectangular web page, whose length L

2017-02-01 16:42:33 232

原创 LEETCODE--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

2017-02-01 12:37:21 202

原创 LEETCODE--Sum of Two Integers

Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Example: Given a = 1 and b = 2, return 3. 参考自 思路: 这里用到了一个半加法的思想, 即两位单独的位相加其结果可以用异或得到, 进位可以用与得到. 然后对于

2017-02-01 11:49:13 156

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除