上一页 1 ··· 5 6 7 8 9 10 11 下一页
方法一:不进行夹逼,直接使用类似2Sum的方法,使用一个hashTable,键值对应vector中的数值,value对应vector对用数值的索引,这其中有一个小trick:最外层的循环需要出力重复数字,但是再深一层的循环判断重复数字时需要避开最外层循环的数字,如处理(-1, -1, 2)这种情况 Read More
posted @ 2017-03-09 23:15 chengcy Views(516) Comments(0) Diggs(0)
Implement strStr().Returns a pointer to the first occurrence of needle in haystack, ornullif needle is not part of haystack.思路:时间复杂度O(m*n),也就是BF(Brute... Read More
posted @ 2014-10-29 14:03 chengcy Views(118) Comments(0) Diggs(0)
Given two binary strings, return their sum (also a binary string).For example,a ="11"b ="1"Return"100".思路简单(同Add Two Numbers),可从代码得知,需要注意字符在字符串中的插入;co... Read More
posted @ 2014-10-28 21:18 chengcy Views(117) Comments(0) Diggs(0)
erase():erase函数的原型如下:(1)string& erase ( size_t pos = 0, size_t n = npos );(2)iterator erase ( iterator position );(3)iterator erase ( iterator first, ... Read More
posted @ 2014-10-27 19:58 chengcy Views(260) Comments(0) Diggs(0)
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.//数字或字母For example,"A man, a plan, a cana... Read More
posted @ 2014-10-27 19:44 chengcy Views(112) Comments(0) Diggs(0)
Given a list, rotate the list to the right bykplaces, wherekis non-negative.For example:Given1->2->3->4->5->NULLandk=2,return4->5->1->2->3->NULL.思路:将单... Read More
posted @ 2014-10-26 21:04 chengcy Views(100) Comments(0) Diggs(0)
Given an arraySofnintegers, find three integers inSsuch that the sum is closest to a given number, target. Return the sum of the three integers. You m... Read More
posted @ 2014-10-25 21:16 chengcy Views(127) Comments(0) Diggs(0)
Given an arraySofnintegers, are there elementsa,b,cinSsuch thata+b+c= 0? Find all unique triplets in the array which gives the sum of zero.Note:Elemen... Read More
posted @ 2014-10-25 20:38 chengcy Views(179) Comments(0) Diggs(0)
Given a linked list and a valuex, partition it such that all nodes less thanxcome before nodes greater than or equal tox.You should preserve the origi... Read More
posted @ 2014-10-25 14:31 chengcy Views(96) Comments(0) Diggs(0)
Given a sorted linked list, delete all duplicates such that each element appear onlyonce.For example,Given1->1->2, return1->2.Given1->1->2->3->3, retu... Read More
posted @ 2014-10-24 15:52 chengcy Views(88) Comments(0) Diggs(0)
上一页 1 ··· 5 6 7 8 9 10 11 下一页