码迷,mamicode.com
首页 >  
搜索关键字:two pointers    ( 12138个结果
two sum
Question 1:Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of...
分类:其他好文   时间:2014-05-19 09:35:41    阅读次数:321
[leetcode]_Merge Two Sorted Lists
题目:合并两个有序单链表思路:一开始想复杂了,以为必须在原链表上修改(绕来绕去还AC了,但是思路相当绕),其实没有,按照正常地合并两个数组同样的方法也对。代码:public ListNode mergeTwoLists(ListNode l1, ListNode l2) { if(l1 ...
分类:其他好文   时间:2014-05-19 07:48:32    阅读次数:314
Classic Abstract Data Types--C
本文内容来自《pointers on C》栈的接口/* Interface for a stack module */#define STACK_TYPE intvoid push(STACK_TYPE value);void pop(void);STACK_TYPE top(void);in...
分类:其他好文   时间:2014-05-18 20:37:48    阅读次数:509
LeetCode: Divide Two Integers [028]
【题目】 Divide two integers without using multiplication, division and mod operator. 【题意】 计算两个数的商,不能使用乘、除、取余操作 【思路】 用加法,确定多少除数相加其和恰好<=被除数 为了提高算法效率,利用贪心思想,采用滚雪球式的翻倍叠加策略,使和快速逼近被除数 集中特殊情况需要注意: 1. 结果是负数 ...
分类:其他好文   时间:2014-05-18 10:42:00    阅读次数:259
LeetCode: Swap Nodes in Pairs [023]
【题目】 Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2->3->4, you should return the list as 2->1->4->3. Your algorithm should use only constant space. You may not modify the values in the list, only nodes it...
分类:其他好文   时间:2014-05-18 08:37:57    阅读次数:370
[leetcode]:Two Sum
题目:给定一个数组,以及一个 target 值,target 表示目标和,要求在数组中找到两个数,xi,xj,使得 xi + xj = target。返回值是找到的两个数的下标索引,升序排序。假定至少存在一对解。 分析:对于要处理数组的问题,我们的理想状态都是给定的数组是有序的就好了,在有序后,我们就可以首位各放一个标记。类似于二分查找。 vector twoSum(vector &n...
分类:其他好文   时间:2014-05-18 08:04:03    阅读次数:234
HDU-4734-F(x)
Problem Description For a decimal number x with n digits (AnAn-1An-2 ... A2A1), we define its weight as F(x) = An * 2n-1 + An-1 * 2n-2 + ... + A2 * 2 + A1 * 1. Now you are given two numbers A and...
分类:其他好文   时间:2014-05-18 06:35:50    阅读次数:300
【LeetCode】Multiply Strings
Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-nega...
分类:其他好文   时间:2014-05-18 01:25:07    阅读次数:288
CareerCup之1.8 字符串移位包含问题
【题目】 原文: 1.8 Assume you have a method isSubstring which checks if one word is a substring of another. Given two strings, s1 and s2, write code to check if s2 is a rotation of s1 using only one...
分类:其他好文   时间:2014-05-16 01:50:08    阅读次数:311
LeetCode 011 Container With Most Water
【题目】 Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a contain...
分类:其他好文   时间:2014-05-16 01:32:47    阅读次数:406
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!