整數的二進位表達中有多少個1__二進位

//整數的二進位表達中有多少個1public class CountOne{ //方法一public static int Count01(int n){int res=0;while(n!=0){res+=n&1;n>>>=1;}return res;} //方法二 public static int Count02(int n) { int sum=0; while(n!=0) { n=n&(

通過位元運算實現兩個數的加、減、乘、除__位元運算

//通過位元運算實現兩個數的加、減、乘、除public class BitSuan{ //(1)加法運算 public static int add(int a,int b) { int sum=a; while(b!=0) { //a與b無進位相加 sum=a^b; b=(a&b)<<1; a=sum; } return sum; } /

找到兩個排序數組的中位元__class

//找到兩個排序數組的中位元public class GetMedianTwoArr{//k為中位元的位置 public static double findKth(int a[], int m, int b[], int n, int k){//always assume that m is equal or smaller than nif (m > n)return findKth(b, n, a, m, k);if (m == 0)return b[k - 1];if (k ==

不用任何比較判斷找出兩個數中較大的數__不用任何比較判斷找出兩個數中較大的數

//不用任何比較判斷找出兩個數中較大的數public class TwoNumWithoutJudge{ //判斷一個數的符號(返回0負數,1為正數) public static int GetSign(int x) { return ((x>>31)^1)&1; } //方法1 (局限性前提a與b不相等,可能溢出) public static int GetMax01(int a,int b) {

字串的統計字串__string

//字串的統計字串public class GetCoutString{//統計字串public static String getCountString(String str){if(str==null||str.equals("")){return "";}char[]chs=str.toCharArray(); //字串轉換成數組String res=String.valueOf(chs[0]);int num=1;for(int i=1;i<

替換字串中連續出現的指定字串__替換字串中連續出現的指定字串

//替換字串中連續出現的指定字串public class ReplaceString{//替換指定的字串(from 字串替換成to字串)public static String replaceString(String str,String from,String to){if(str==null||from==null||str.equals("")||from.equals("")){return

判斷兩個字串是否互為旋轉詞__string

//判斷兩個字串是否互為旋轉詞public class IsRotate{//互為旋轉詞public static boolean isRotate(String str1,String str2){if(str1==null||str2==null||str1.length()!=str2.length()){return false;}String str=str2+str2;return getIndexOf(str,str1)!=-1;

去掉字串中連續出現k個0的子串__class

//去掉字串中連續出現k個0的子串public class RemoveKZeros{//返回去掉k個0後的字串public static String removeKZeros(String str,int k){ if(str==null||k<1) { return str; } //字串轉換成數組 char[]ch=str.toCharArray(); int

字串中數字子串的求和__遍曆

//字串中數字子串的求和public class NumSum{//字串中數字子串的求和public static int numSum(String str){if(str==null){return 0;}//字串轉換成數組char[]charArr=str.toCharArray();int res=0;//目前的累加和int num=0; //當前收集到的數字boolean posi=true; //num累加到res裡,num是正還是負int

判斷兩個字串是否互為變形詞__boolean

//判斷兩個字串是否互為變形詞public class BianString{//判斷字串互為變形詞public static boolean isDeformation(String str1,String str2){if(str1==null||str2==null||str1.length()!=str2.length()){return

N皇后問題__N皇后問題

//N皇后問題public class NQueue{//暴力遞迴法public static int num01(int n){if(n<1){return 0;}int[]record=new int[n];return process01(0,record,n);}public static int process01(int i,int[]record,int n){if(i==n){return 1;}int res=0;for(int

數組中的最長連續序列__hashmap

import java.util.*;//數組中的最長連續序列public class LongestSequence{//最長的連續序列 public static int longestConsecutive(int[]arr) { if(arr==null||arr.length==0) { return 0; } int max=1; //key 表示遍曆的某個數 value表示最長連續序列的長度

跳躍遊戲__遊戲

//跳躍遊戲public class JumpGame{public static int jump(int[]arr){if(arr==null||arr.length==0){return 0;}int jump=0; //目前跳了多少步int cur=0; //最遠能夠到達的位置int next=0; //多跳一步,最遠能夠到達的位置for(int

排成一條線的紙牌博弈問題__排成一條線的紙牌博弈問題

//排成一條線的紙牌博弈問題public class CardProblem{//暴力遞迴方法(時間複雜度O(2^n),空間複雜度O(n))public static int win01(int[]arr){if(arr==null||arr.length==0){return 0;}return Math.max(f(arr,0,arr.length-1),s(arr,0,arr.length-1));}//先選的最優函數public static int f(int[]arr,int

運算式得到期望結果的組成種數__動態規劃

//運算式得到期望結果的組成種數public class ExpreeNum{//判斷是否是有效運算式public static boolean isValid(char[]exp){//運算式的長度必須是奇數if((exp.length&1)==0){return false;}//偶數位置必須為0或1for(int i=0;i<exp.length;i+=2){ if((exp[i]!='0')&&(exp[i]!='1'))

二叉樹節點間的最大距離問題__二叉樹

//二叉樹節點間的最大距離問題public class MaxDistanceOfTree{//二叉樹節點的定義public static class Node{public int value;public Node left;public Node right;public Node(int data){this.value=data;}}//獲得一個二叉樹兩個節點間的最大距離/** 最大子樹的長度為:左子樹最大長度+右子樹最大長度+1*/public static int

TarjanAndDisjointSetsForLCA解決批量查詢問題__函數

import java.util.HashMap;import java.util.LinkedList;public class TarjanAndDisjointSetsForLCA {public static class Node {public int value;public Node left;public Node right;public Node(int data) {this.value = data;}}public static class Query {public

在二叉樹中找到兩個節點的最近公用祖先__遞迴

import java.util.*;//在二叉樹中找到兩個節點的最近公用祖先public class GetLowestTree{//二叉樹節點的定義public static class Node{public int value;public Node left;public Node right;public Node(int data){this.value=data;}}//找到兩個節點的最近公用祖先public static Node GetLowestAncestor(Node

在二叉樹中找到一個節點的後繼節點__開發人員

//在二叉樹中找到一個節點的後繼節點public class getNextNode{//節點的定義public static class Node{public int value;public Node left;public Node right;public Node parent;public Node(int data){this.value=data;}} //給定一個節點獲得其後繼節點public static Node getNextNode(Node

通過有序數組產生平衡搜尋二叉樹__搜尋

//通過有序數組產生平衡搜尋二叉樹public class generateBST{ //二叉樹節點的定義 public static class Node{ public int value; public Node left; public Node right; public Node(int data) { this.value=data; } } //產生平衡二叉搜尋樹

總頁數: 61357 1 .... 23265 23266 23267 23268 23269 .... 61357 Go to: 前往

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.