35. 第一个只出现一次的字符

char firtNotRepeat(char *s)
{
if(s == NULL) return 0;
int i = 0;
while(s[i] != '\0') record[s[i++]] ^= 1;
i = 0;
while(!record[s[i]]) ++i;
return s[i];
}

36.数组中的逆序对个数 (归并排序解法)

#include <iostream>
using namespace std;
void inversePairsCore(int data[], int copy[], int low, int high, int& count)
{
if(low == high) return; int mid = (low + high) / 2;
inversePairsCore(data, copy, low, mid, count);
inversePairsCore(data, copy, mid+1, high, count); int k = high, tag_mid = mid, tag_high = high;
while(low <= mid && tag_mid +1 <= high)
{
if(data[mid] > data[high])
{
copy[k--] = data[mid--];
count += high - tag_mid;
}
else if(data[mid] < data[high])
{
copy[k--] = data[high--];
}
else
copy[k--] = data[high--];
}
while(low <= mid) copy[k--] = data[mid--];
while(tag_mid+1 <= high) copy[k--] = data[high--]; for(k = low; k <= tag_high; ++k)
data[k] = copy[k];
}
int inversePairs(int data[], int length)
{
if(data == NULL && length < 1) return 0; int *copy = new int[length];
int count = 0;
inversePairsCore(data, copy, 0, length-1, count); delete[] copy;
return count;
} int main()
{
int data[] = {4, 4, 4, 3, 3};
printf("%d\n", inversePairs(data, sizeof(data)/4));
return 0;
}

37.  两个链表的第一个公共结点

int getLength(ListNode *pHead)
{
if(pHead == NULL) return 0;
int len = 0;
ListNode *p = pHead;
while(p != NULL)
{
p = p->next;
len ++;
}
return len;
}
ListNode* firstNode(ListNode *pHead1, ListNode* pHead2)
{
if(pHead1 == NULL || pHead2 == NULL) return NULL;
int len1 = getLength(pHead1);
int len2 = getLength(pHead2);
if(len1 < len2) return firstNode(pHead2, pHead1);
int k = len1 - len2;
ListNode *p1 = pHead1, *p2 = pHead2;
while(k > 0)
{
p1 = p1->next;
--k;
}
while(p1 != NULL && p2 != NULL && p1 != p2)
{
p1 = p1->next;
p2 = p2->next;
}
if(p1 == NULL || p2 == NULL) return NULL;
return p1;
}

Chap5: question 35 - 37的更多相关文章

  1. Chap5: question: 29 - 31

    29. 数组中出现次数超过一半的数字. 方法a. 排序取中       O(nlogn). 方法b. partition 函数分割找中位数     >=O(n). 方法c. 设计数变量,扫描一遍 ...

  2. 地上有一个m行和n列的方格。一个机器人从坐标0,0的格子开始移动,每一次只能向左,右,上,下四个方向移动一格,但是不能进入行坐标和列坐标的数位之和大于k的格子。 例如,当k为18时,机器人能够进入方格(35,37),因为3+5+3+7 = 18。但是,它不能进入方格(35,38),因为3+5+3+8 = 19。请问该机器人能够达到多少个格子?

    // test20.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<iostream> #include< ...

  3. 【35.37%】【codeforces 556C】Case of Matryoshkas

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. ethereum/EIPs-155 Simple replay attack protection 35,36

    EIP 155:重放攻击保护——防止了在一个以太坊链上的交易被重复广播到另外一条链. 在看椭圆曲线时有提到,与r.s.v中的v相关 不同的共有链定义不同的chainId, 防止同一笔交易在不同的共有链 ...

  5. 1Z0-050

    QUESTION 13 View the Exhibit.Examine the following command that is executed for the TRANSPORT table ...

  6. OCJP(1Z0-851) 模拟题分析(二)over

    Exam : 1Z0-851 Java Standard Edition 6 Programmer Certified Professional Exam 以下分析全都是我自己分析或者参考网上的,定有 ...

  7. Sharepoint学习笔记—习题系列--70-573习题解析 -(Q35-Q39)

    Question 35You have a custom Web Part that is deployed as a sandboxed solution.You need to ensure th ...

  8. LoadRunner面试题

    在LoadRunner中为什么要设置思考时间和pacing 答: 录制时记录的是客户端和服务端的交互,如果要精确模拟 用户的行为,那么客户操作客户端时花费了很多时间要怎么模拟呢?录入 填写提交的内容, ...

  9. 雅虎公司C#笔试题及参考答案

    Question 1. (单选) 在计算机网络中,表征数据传输可靠性的指标是——21. 传输率2. 误码率3. 信息容量4. 频带利用率Question 2. (单选) 以下关于链式存储结构的叙述中哪 ...

随机推荐

  1. sqlite以及python的应用

    有点乱,自己平时,遇到了就记下来,所以没整理. 数据库sqlite,以及Qt对数据库的操作 sql学习网址: sqlite官网:http://www.sqlite.org http://www.w3s ...

  2. ant sshexec 无法启动tomcat

    1.如果./startup.sh启动不了,可以试试./catalina.sh run 2.这个两个都是调用的catalina里边的方法,只不过一个重定向了日志,一个没有 eval \"$_R ...

  3. realestate.cei.gov.cn

    using AnfleCrawler.Common; using System; using System.Collections.Concurrent; using System.Collectio ...

  4. [UIImage resizableImageWithCapInsets:]

    [UIImage resizableImageWithCapInsets:]使用注意 转自:http://www.cnblogs.com/scorpiozj/p/3302270.html 最近在sae ...

  5. 对编写html代码的几点儿小建议

    1.DOCTYPE说明:告诉浏览器要使用哪种规范来解释该文档内容: <!DOCTYPE html PUBLIC "-W3//DTD//XHTML 1.0  Transitional// ...

  6. css+div

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  7. 关于kindeditor中点击图片后,滚动条往上顶的bug

    比如现在我插入两张图片, 无论我点击哪张图片,里边的滚动条都会往上顶. 本来以为往上会有解决方法,一查结果没有:然后想着去官网查查,然而什么都没有,想到官网提交这个bug,结果没地方提交. 怎么解决, ...

  8. mysql事务,SET AUTOCOMMIT,START TRANSACTION

    http://yulei568.blog.163.com/blog/static/135886720071012444422/ MyISAM不支持 START TRANSACTION | BEGIN ...

  9. 怎样用JS获取ASP.NET服务器控件的客户端ID

    虽然简单,不过曾经困扰多时,还是记录一下吧. 来源:http://mou518.blog.163.com/blog/static/1756052222010111434428828/ 因为经常服务器控 ...

  10. Node.js网络编程

    Node.js为javascript语言提供了一个在服务端运行的平台,它以其事件驱动,非阻塞I/O机制使得它本身非常适合开发运行在在分布式设备上的I/O密集型应用,分布式应用要求Node.js必须对网 ...