原创 strtok 分割字符串

#include<stdio.h> #include<stdlib.h> #include<string.h> int main(){ char ch[]="I\nam\nstudent"; char *tok=NULL; t

原创 循環數組中查找一個數

int findRes(int a[],int l,int r,int x); int bsearch(int a[],int l,int r,int x); int findFunc(int a[],int n,int x){ if

原创 二叉樹-最近公共祖先(LCA)

思路:遞歸的思想,如果當前節點的左子樹和右子樹各包括一個節點,則該節點就爲最近公共祖先;如果當前節點等於其中的一個節點,則當前節點爲最近公共祖先;如果當前節點的左子樹或者右子樹包括兩個節點,則需要遞歸求該節點的左子樹或者有子樹。 str

原创 1.2

Write code to reverse a C-Style String. (C-String means that “abcd” is represented as five characters, including the nu

原创 2.2

Implement an algorithm to find the nth to last element of a singly linked list. 分析:查找鏈表倒數第n個元素,這在劍指offer上有相同的習題 Node* g

原创 hdu 2686

這個題目在面試的時候被問到了,首先問我的是一個人版本的,然後增加到兩個人版本的。 題目的含義是:一個n*n的棋盤,每個棋盤上有金礦,該金礦拿走後就沒有了,問一個人從(0,0)->(n,n)然後再從(n,n)->(0,0)(這次的路徑不能和

原创 2.4

You have two numbers represented by a linked list, where each node contain

原创 實習中用到的Linux命令總結

1、ps -ef  查看進程,經常通過管道和grep連用 2、netstat -an 顯示網絡中所有連接的端口並用數字表示 3、lsof -i:端口號  查看佔用該端口號的進程 4、scp libsoambase.so [email protected]

原创 1.6

Given an image represented by an NxN matrix, where each pixel in the image is 4 bytes, write a method to rotate the ima

原创 1.4

Write a method to decide if two strings are anagrams or not. 思路:使用一個count記錄每個字符出現的次數,若出現的次數都相同,說明兩個詞是變位詞 bool isStringA

原创 1.3

Design an algorithm and write code to remove the duplicate characters in a string without using any additional buffer.

原创 1.8

Assume you have a method isSubstring which checks if one word is a substring of another. Given two strings, s1 and s2,

原创 堆中插入元素

只需要將最後一個位置++,將插入的值放入最後一個位置中,然後向上進行調整 代碼如下(最大堆): int cnt=0; int heap[1000]; void heapInsert(int x){ cnt++; heap[cnt]

原创 2.5

Given a circular linked list, implement an algorithm which returns node at

原创 1-n個元素中查找缺失的一個數

題意:已知一個有序數列1-n(元素值)中缺少了一個元素,找出這個元素。 1、異或可解 時間複雜度O(n) 2、二分 時間複雜度O(lgn) 代碼如下: //二分查找有序數組中缺失的一個元素,時間複雜度儘可能低 int bsearch(