首页 > 其他 > 详细

[Daily Coding Problem 371] Solve Arithmetic Equations

时间:2019-12-04 16:18:09      阅读:99      评论:0      收藏:0      [点我收藏+]

You are given a series of arithmetic equations as a string, such as:

y = x + 1
5 = x + 3
10 = z + y + 2

The equations use addition only and are separated by newlines. Return a mapping of all variables to their values. If it‘s not possible, then return null. In this example, you should return:

{
  x: 2,
  y: 3,
  z: 5
}



The solution offered by Daily Coding Problem is a simpified version, and incorrect when there is no single-variable equation or there are conflicting single-variable equations.
Solving a system of linear equations is a lot more involved than that. Refer to the following for more information.

https://en.wikipedia.org/wiki/Gaussian_elimination
https://www.geeksforgeeks.org/gaussian-elimination/

[Daily Coding Problem 371] Solve Arithmetic Equations

原文:https://www.cnblogs.com/lz87/p/11982096.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!