Sword refers to Offer interview question 10 (Java edition): number of 1 in binary, and sword refers to offer
Question: Please implement a function, input an integer, and output this number in binary format to represent the number of 1. For example, if 9 is expressed as binary 1001, two digits are 1. Therefore, if 9 is input, this function outputs 2.
1. solutions that may cause an endless loop
This is a basi
Sword refers to offer interview question 14 (Java edition): Adjust the array order so that the odd number is in front of the even number, the sword refers to offer
Question: enter an integer array and implement a function to adjust the order of numbers in the array so that all odd numbers are in the first half of the array, and all even numbers are in the second half of the array.
1. Basic implementation:
I
Quick sorting and optimization (Java Edition)
Quicksort is an improvement in Bubble sorting. Quick sorting was proposed by C. A. R. Hoare in 1962.
Detailed process of a quick sort:Select the first value of the array as the pivot value.
Code implementation:
Package QuickSort; public class QuickSortRealize {public static void QuickSort (int [] arr) {QSort (arr, 0, arr. length-1);} // sort the subsequences of
Common linked list questions (java Edition)
Dry goods directly .....
Common linked list questions:Find the last k nodes of a single-chain table. Delete a node (O (1) in a single-chain table )). Reverse the linked list. The first public node of the two linked lists. The Start Node of the loop returned from the chain table (and whether the ring exists ). Merge two sorted linked lists. Delete duplicate nodes i
I. Where the object is saved
Register (CPU)
Stack (variable)
Heap (object)
Static domain (statics)
Chang (String)
Non-memory Zone pool
Two. Basic data typesInteger byte short int long 8 16 32 64Float type float Double 32 64Character Char-UnicodeBoolean Type Boolean 1Three. Static belongs to a class call that does not belong to an object (many in a generic tool class)Thinking in Java (fourth
to find the number of points, good time performanceTo solve the problem in a different way, we can consider using two arrays to store the number of occurrences of each review of the dice points. In a single loop. The nth number in each array represents the number of times the dice and N appear.In the next round of loops, we add a new dice, and the number of occurrences of n at this time. In the next round, we add a new dice, at this time and the dice for n should be equal to the number of dice
Q: What is Object-oriented? What is the difference from a process-oriented one?A: Object-oriented: The problem-oriented space, based on the abstraction of the problem;Process oriented: The solution space, based on the computer structure to abstract;Five basic features of OOP:1) All things are objects.ExplainYou can extract any conceptualization artifacts that you want to solve for a problem and represent them as objects in your program.2) programs are collections of objects that they communicate
recursive process.Java code Implementation steps such as the following:/** * */package swordforoffer;/** * @author Jinshuangqi * * August 8, 2015 */public class E29morethanhalfnumber {//applicable partition function public int partition (int[] Arr,int left,int right) {int result = Arr[left];if (Left > right) return-1;while (left solution Two: According to the characteristics of the array to find O (n) algorithm:Next we will solve the problem from another angle.There is a number in the array tha
Package Com.love.test;import java.util.scanner;/** * @author Huowolf * Select Sort Implementation * Thought: Each trip selects the keyword smallest record from the sequence of records to be sorted and places it to the first position of the sorted table until all rows are completed.*/public class Selectsort {public static void Selectsort (int[] arr) {for (int i=0;i Select Sort (Java edition)
element that is smaller than the Datum element3 intStoreindex = 0;4 //default takes the first element as a datum element5 intPivot =A[low];6 //first move the datum element to the end of the array7 intTMP =A[low];8A[low] = a[a.length-1];9A[A.LENGTH-1] =tmp;Ten //will be smaller than the base element, followed by a larger than the base element. One for(inti = 0; i ) { A if(A[i] pivot) { - inttemp =A[i]; -A[i] =A[
")); C.add (NewString ("CCC")); C.add (NewString ("ddd")); C.add (NewString ("FFF")); C.add (NewString ("Eee")); for(Object o:c) {//System.out.print (o + ""); if(O.equals ("FFF") {c.remove (o); }} System.out.println (c);}When we run this program, you will find out how the string object "FFF" was successfully deleted?! This is where I have been puzzled and slightly idiot. In fact, I can conclude that when iterating through an iterator, the second-to-last element in the container object mu
??Introduction??Generally this can not be used with the arithmetic of the problem are only to use the bit operation to do, the purpose is to strengthen everyone's understanding of computer computing, it is a bit of a nonsense??Solve the problem??First we have to think about how computers do additions, such as 3 plus 4, if the conversion to binary is 0011 and 0100, plus 7, which is 0111. , which is equivalent to two binary XOR operations??But let's take another example, 4 plus 4, and we'll find
)%n??Then the mapping is the same as the original problem, that is F(n-1,m)??i.e. P(f ' (n-1,m) =f (n-1,m)??And now we only have a relationship between F(n,m) and F ' (N-1,M)??So we need to switch again, and we'll find the inverse of the map.????and the inverse map of the map p is??O (Y)-->x x= (y+k+1)%n??Where K can replace k%n= (m-1)%n??i.e. o (y)-->x x= (y+m)%n??Corresponds to the relationship between the previous F (n-1,m) and F ' (n-1,m)??F ' (n-1,m) =f (n-1,m) +m%n??and??F (n,m) =f ' (n-1,
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.