1. ???? ??
[??]
?? ???? ??? n?? ??? ???? ???. (0?? ???? 0?? ??? 0???.) ).
(?? ??? ????: java ??)
[Code]
package swear2offer.array; public class FeiBoNaQi { /** * 大家都知道斐波那契數(shù)列,現(xiàn)在要求輸入一個(gè)整數(shù) n, * 請(qǐng)你輸出斐波那契數(shù)列的第 n 項(xiàng)(從 0 開(kāi)始,第 0 項(xiàng)為 0)。 * 0,1,1,2,3,5 * n<=39 * */ public int Fibonacci(int n) { if (n == 0) return 0; if (n == 1 || n== 2) return 1; return Fibonacci(n-1) + Fibonacci(n-2); } /** * 非遞歸方式,遞歸的數(shù)據(jù)結(jié)構(gòu)使用的棧,那就是使用棧的方式 * */ public int NoRecursive(int n) { if (n>2) { int[] a = new int[n+1]; a[0] = 0; a[1] = 1; a[2] = 1; for (int i=3; i<=n; i++) { a[i] = a[i-1] + a[i-2]; } return a[n]; } else { if (n == 0) return 0; else return 1; } } public static void main(String[] args) { System.out.println(new FeiBoNaQi().Fibonacci(39)); System.out.println(new FeiBoNaQi().Fibonacci(39)); } }
2. ???? ??
[??]
21?? ?? ????? ???? ?? ?? ??? ? ? ????? ?? ? ????. ??? 2*n? ? ????? ??? 21? n?? ?? ?????? ??? ?? ?? ??? ? ??????
?? ?? n=3? ?? 2*3 ???? ???? 3?? ?? ??? ????.
??:
package swear2offer.array; public class Rectangle { /** * f[0] = 0; * f[1] = 1; * f[2] = 2; * f[3] = 3; * f[4] = 5; * f[5] = 8; * f[n] = f[n-1] + f[n-2] * */ public int RectCover(int target) { if (target < 4) return target; int[] f = new int[target + 1]; int i; for (i=0; i<4; i++) f[i] = i; for (i=4; i<=target; i++) { f[i] = f[i-1] + f[i-2]; } return f[target]; } public static void main(String[] args) { System.out.println(new Rectangle().RectCover(5)); } }
[Thinking]
??? ???? ?? ??? ??? ??? ?? ????. , ??? ??? ?? ??? ???? ??? ???? ???? ? ? ???, ?? ??? ??? ??? ?? ?? ?? n? ??? ?? ???? ???? ????. n-1? ???? ? ?? ??? ??(f[n-2])?? ??(f[n-1])?? ??? ??? ?????.
(?? ??? ?? ??: java ??? ?? ? ??)
3.2?? 1
[??]
??? ???? 1? ??? ???? ?????. ??? 2? ??? ?????.
【??】
package swear2offer.array; public class Binary { /** * 輸入一個(gè)整數(shù),輸出該數(shù)二進(jìn)制表示中 1 的個(gè)數(shù)。其中負(fù)數(shù)用補(bǔ)碼表示。 * */ public int NumberOf1(int n) { int count; count = 0; while(n != 0) { n = n & (n-1);// 與操作就是二進(jìn)制的操作,適用原碼和補(bǔ)碼 count ++; } return count; } }
【??】
??? ?? ??: ?? ??? ??? ????, ??? ??? ?????. ??? ??: ?? ??? ???? +1.
??? 0? ?? ?? ? ??? ?? ? ??? 1???. ? ???? 1? ?? ??? ?? ???? ?? ?? 1? 0? ??, ?? 1 ?? ?? 0? 1? ???(?? ??? 1 ?? 0? ?? ??). ??? ?? ??? ??? ?? ????.
?: ??? 1100? ?? ????? ? ?? ??? ?? ??? 1???. 1? ?? ? ?? ??? 0? ??, ???? ? ?? 0? 1? ??, ? ?? 1? ??? ?? ???? ??? 1011? ???. 1? ? ??? ?? ???? ??? ??? ??? ? ? ????. 1? ???? ?? ??? ???. ??, ?? ??? 1? ? ??? AND ???? ?? ??? ?? ??? 1?? ???? ?? ??? 0? ???. ?? ??, 1100&1011=1000 ?, ???? 1? ? ?? ?? ??? AND ??? ???? ??? ?? ???? ?? 1? 0?? ????. ??? 1? ???? ????. ??? ?? ???? ?? ?? ?? ?????.
4. ?? ?? ????
[??]
double ??? ?? ??? ?? ??? int ??? ?? ??? ?????. ????? ????? ??? ????.
??? ??? ??? 0? ??? ?????
[Code]
package swear2offer.array; public class Power { public double Power(double base, int exponent) { if (base == 0) return 0; if (exponent == 0) return 1; int count; boolean flag; double temp; count = 1; temp = base; flag = true;// 標(biāo)記正負(fù) if (exponent < 0){ exponent = -exponent; flag = false; } while (count < exponent) { base *= temp; count ++; } if (flag) { return base; } else { return 1/base; } } public static void main(String[] args) { System.out.println(new Power().Power(2,-3)); } }
[Thinking]
? ??? ??? ??, ????? ?? ???? ???, ???? ??? ????
? ?? ???? ?????. ??? ??? ??? ??? ????
??, ??==0? ??==0? ??? ????
????? ??? ??? ? ??? ??? ? ????. ???? ?? ??? ???.
5. ??? ?? ?? ??? ??? ??? ?????
[Title]
?? ??? ???? ??? ?? ??? ???? ??? ?????. ?? ??? ??? ? ?? ??? ?? ?? ??? ??? ? ?? ??? ???, ??? ??, ??? ?? ??? ?? ??? ???? ?? ??? ????? ?????.
[??]
package swear2offer.array; import java.util.Arrays; public class OddEven { /** * 輸入一個(gè)整數(shù)數(shù)組,實(shí)現(xiàn)一個(gè)函數(shù)來(lái)調(diào)整該數(shù)組中數(shù)字的順序, * 使得所有的奇數(shù)位于數(shù)組的前半部分,所有的偶數(shù)位于數(shù)組的后半部分, * 并保證奇數(shù)和奇數(shù),偶數(shù)和偶數(shù)之間的相對(duì)位置不變。 * * 時(shí)空復(fù)雜度較高的算法: * 新建一個(gè)數(shù)組b,用來(lái)保存奇數(shù),在重新變量一次,保存偶數(shù) * 時(shí)空復(fù)雜度0(n) * */ public void reOrderArray1(int [] array) { int n,i,j; n = array.length; int[] b = new int[n]; j = 0;// 用來(lái)保存數(shù)組B的下標(biāo) for (i=0; i<n; i++) { if (array[i]%2 != 0) { b[j] = array[i]; j ++; } } for (i=0; i<n; i++) { if (array[i]%2 == 0){ b[j] = array[i]; j++; } } for (i=0; i<n; i++) { array[i] = b[i]; } } /** * 采用的冒泡交換以及快速排序的思想: * 設(shè)定兩個(gè)游標(biāo),游標(biāo)分別用來(lái)標(biāo)記奇數(shù)和偶數(shù)的下標(biāo),然后交換二者 * 注意交換二者是無(wú)法保證順序的,交換的ij之間還有進(jìn)行平移。 * */ public void reOrderArray(int [] array) { int n,i,j,temp,p; n = array.length; i = 0; j = 0; while (i<n && j<n) { // i標(biāo)記偶數(shù)下標(biāo) while (i<n) { if (array[i]%2 ==0){ break; } else { i++; } } j = i; // j標(biāo)記奇數(shù)下標(biāo) while (j<n) { if (array[j]%2 !=0){ break; } else { j++; } } if (i<n && j<n) { // 此時(shí)ij已經(jīng)在遇到的第一個(gè)偶數(shù)和奇數(shù)停下,把ij之間的內(nèi)容平移 temp = array[j]; for (p=j; p>i; p--) { array[p] = array[p-1]; } array[i] = temp; // 此時(shí)把i,j標(biāo)記到 未交換前的偶數(shù)位置的下一個(gè) i ++; j = i; } } } public static void main(String[] args) { int[] a = {1,4,6,3,2,5,8}; int[] b = {2,4,6,1,3,5,7}; new OddEven().reOrderArray(b); System.out.println(Arrays.toString(b)); } }
[??]
??? ? ??? ??? ??? ???? ?????. ? ?? ??? ? ???? ??? ???? ??? ????. . ??, ??? ? ?? ?? ?? ??? ? ??? ??? ?? ?????.
?? ?? ??: Java ????
? ??? Java ???? ???? ?? ?? ??(2)? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

settings.json ??? ??? ?? ?? ?? ?? ?? ??? ??? VSCODE ??? ??? ???? ? ?????. 1. ??? ?? ?? : Windows? C : \ Users \\ AppData \ Roaming \ Code \ User \ Settings.json, MacOS IS /users//library/applicationsupport/code/user/settings.json, linux? /home//.config/code/user/settings.json; 2. Workspace ?? ?? : .vscode/settings project root ????

JDBC ????? ???? ????? ?? ?? ?? ??? ?? ?? ??? ?? ? ?? ??? ?? ?? ?? ??? ???????. 1. ????? ????? Conn.SetAutoCommit (False)?? ??????. 2. ??? ? ????? ?? ?? SQL ??? ?????. 3. ?? ??? ??? ?? Conn.commit ()?? ???? ??? ???? ???? ?? ??? ???? Conn.Rollback ()?? ??????. ???, ? ??? ???? ????, ??? ???? ????, ?? ??? ??? ?? ??? ??? ???? ? ???????. ?? ?? ?? ???? ????? ??? ???? ?? ?? ???? ???? ??? ????? ?? ??? ??? ? ?? ???? ?? ????.

??? (DI) ISADESIGNPATTORNWHEREWHEDROUDIVESTESTESTETESTERGROWCONSTRUCTOR, 2.SPRINGFRAMEWWERTHUSENONTATIONS? ??@autowiredWithjava ?? CONCUTTATIONS LIKERWITHCONSTRUCTOR, ORFIELDINGESS.2.SPRINGFRAMEWWERTHUSENNOTATIONS

thejvmenablesjava? "WriteOnce, Runynywhere"??? ?? excodecodethroughfourmaincomponents : 1. theclassloadersubsystemloads, ??, ? intinitializes.classfilesusingbootsprap, extension, andapplicationclassloaders, ensuringsecureandlazyclasloa

?? ?? ? ?? ???? ???? ?? Java.Time ???? ???? ??????. 2. LocalDate, LocalDateTime ? LocalTime? ?? ?? ??? ??? ?????. 3. () ???? ???? ?? ??? ??? ????. 4. ???/???? ??? ???? ??? ????? ??? ??????. 5. ZonedDateTime ? Zoneid? ???? ???? ??????. 6. DateTimeFormatter? ?? ?? ? ?? ?? ?? ???; 7. ??? ?? ?? ?? ??? ????? ?? ??????. ?? Java? ?? ??? ???? ??? ??? ???? Java.Timeapi ??? ?? ??? ???????.

chromecanopenlocalfiles likehtmlandpdfsbyusing "OpenFile"OrdraggingTheMintoTheBrowser; ensuretHeadDressStartSwithFile : ///; 2.SecurityRestrictionSblockajax, LocalStorage, andcross-folderaccessonfile : //; usealocalsertpython-mhtpython-mhtpython-mhtppy

NetworkPortSandfirewallsworkTogetToenableCommunication whileensuringsecurity.1.networkportSarevirtualendpointsnumbered0–65535, Withwell-nownports like80 (http), 443 (https), 22 (ssh) ? 25 (smtp) ?? (specservices

Pre-FormancetArtUptimeMoryUsage, Quarkusandmicronautleadduetocompile-timeprocessingandgraalvsupport, withquarkusoftenperforminglightbetterine serverless sinarios.2.thyvelopecosyste,
