Answers for "multiply string java"

2

java string multiply

"*".repeat(times);
Posted by: Guest on June-26-2021
1

multiply strings

string Solution::multiply(string A, string B) 
{    
  vector<int> arr(A.size()+B.size(),0);    
  for(int i=A.size()-1;i>=0;i--)    
  {        
    for(int j =B.size()-1;j>=0;j--)        
    {            
      int x = (B[j]-'0')*(A[i]-'0')+arr[i+j+1];           
      arr[i+j+1] = x%10;            
      arr[i+j] += x/10;        
    }    
  }    
  int i=0;    
  while(i<arr.size())    
  {        
    if(arr[i]!=0)            
      break;            
    i++;    
  }                
  if(i == arr.size())        
    return "0";                
  string s = "";        
  for(int j=i;j<arr.size();j++)        
    s += to_string(arr[j]);            
  return s;    
}
Posted by: Guest on October-09-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language