資料結構與演算法練習(Java實現)

2021-08-07 06:01:19 字數 3277 閱讀 1404

package lintcode;

/*** 

* @classname: solution 

* @description: todo() 

* @author a18ccms a18ccms_gmail_com 

* @date 2023年8月14日 上午10:12:29 **/

public class solution

public static void syso(object object)

/*** 

* @title: strstr 

* @description: todo(對於乙個給定的 source 字串和乙個 target 字串,

* 你應該在 source 字串中找出 target 字串出現的第乙個位置(從0開始)。

*   如果不存在,則返回 -1。) 

* @param @param source

* @param @param target

* @param @return    設定檔案 

* @return int    返回型別 

* @throws

*/public static int strstr(string source, string target)

int i, j;

for (i = 0; i < source.length() - target.length() + 1; i++)

}if (j == target.length())

}return -1;

}/**

* * @title: removeelement 

* @description: todo(給出乙個陣列 [0,4,4,0,0,2,4,4],和值 4

*返回 4 並且4個元素的新陣列為[0,0,0,2]) 

* @param @param a

* @param @param elem

* @param @return    設定檔案 

* @return int    返回型別 

* @throws

*/public int removeelement(int a, int elem)

return 1;

}return 0;

}/** 

* @title: isunique 

* @description: todo(//判斷字串是否重複) 

* @param @param str

* @param @return    設定檔案 

* @return boolean    返回型別 

* @throws 

*/public static boolean isunique(string str)

char elements=str.tochararray();  

for(char e:elements)

}return true;

}/** 

* @title: aplusb 

* @description: todo(兩數相加) 

* @param @param a

* @param @param b

* @param @return    設定檔案 

* @return int    返回型別 

* @throws 

*/public static int aplusb(int a, int b)

/** 

* @title: movezeroes 

* @description: todo(給乙個陣列 nums 寫乙個函式將 0 移動到陣列的最後面,非零元素保持原陣列的順序) 

* @param @param nums    設定檔案 

* @return void    返回型別 

* @throws 

*/public static void movezeroes(int nums)

/*** 

* @classname: listnode 

* @description: todo( 將兩個排序鍊錶合併為乙個新的排序鍊錶) 

* @author a18ccms a18ccms_gmail_com 

* @date 2023年8月14日 上午10:15:50 **/

public class listnode  

public listnode merge(listnode list1,listnode list2)  

else  

return list0;  

}  }/**

* * @title: ispalindrome 

* @description: todo(回文數判斷) 

* @param @param x

* @param @return    設定檔案 

* @return boolean    返回型別 

* @throws

*/public static boolean ispalindrome(int x) else

return false;}}

/**/

public static string replacespace(stringbuffer str) else     

--len;

}return new string(ptr);}/*

* 在乙個長度為n的陣列裡的所有數字都在0到n-1的範圍內。 陣列中某些數字是重複的,但不知道有幾個數字是重複的。

* 也不知道每個數字重複幾次。請找出陣列中任意乙個重複的數字。 例如,如果輸入長度為7的陣列,

* 那麼對應的輸出是第乙個重複的數字2

*/public boolean duplicate(int numbers,int length,int duplication)

numbers[index] += length;//由於數字都是0到length -1範圍內的,將以遍歷到的數字為下標的元素加上length

}return false;}/*

* 給定乙個二叉樹,找到其最大深度。最大深度是從根節點到最遠葉節點的最長路徑中的節點數

*//* public int maxdepth(treenode root)*/

/** 請實現乙個演算法,確定乙個字串的所有字元是否全都不同。這裡我們要求不允許使用額外的儲存結構。

*/public static boolean checkdifferent(string inistring) else }}

return true;}}

Java資料結構與演算法

1.1 概念資料結構主要是研究程式設計問題中計算機的操作物件以及它們之間的關係和操作的學科。1.2 分類儲存結構 存在於計算機世界的物理層面 邏輯結構 一種是資料結構的邏輯層面 1.3 按照資料元素分類線性 存在於計算機世界的物理層面 非線性 一種是資料結構的邏輯層面 1.4 集合結構只考慮資料元素...

資料結構與演算法分析Java版練習1 6

package ch01 練習1.6 編寫帶有下列宣告的例程 public void permute string str public void permute char str,int low,int high 第乙個例程是個驅動程式,它呼叫第二個例程並顯示string str中的字元的所有排列...

資料結構與演算法分析Java版練習1 13

package ch01 練習1.13 設計乙個泛型類collection,它儲存object物件的集合 在陣列中 以及該集合的大小。提供public方法 isempty,makeempty,insert,remove和ispresent。方法ispresent x 當且僅當在該集合中存在 由equ...