The number of algorithmic problems in JavaScript

Number of orders

Given 2 * n + 1numbers, in addition to which a number of other figures are each appear twice, to find this number.
Sample
sample 1:

Input: [1,1,2,2,3,4,4]
Output: 3
Explanation:
3 appears only once
Example 2:

Input: [0,0,1]
Output: 1
Explanation:
1 appears only once, the
code
does not use sort() for performance considerations

const singleNumber = function(A){
    
    
	let pdA;
	for(var x=0;x<A.length;++x){
    
    
		pdA=true;
		if(A[x]!==undefined){
    
    
			for(var y=x+1;y< A.length;++y){
    
    
				if(A[x]==A[y]){
    
    
					pdA=false;
					A[y]=undefined;
					break;
				}
			}
			if(pdA){
    
    
				return A[x];
			}
		}
	}
	return -1;
}

Guess you like

Origin blog.csdn.net/qq_37904407/article/details/108897440