Middle-题目116:224. Basic Calculator

本文介绍了一个简单的表达式计算器实现,该计算器能解析包含加减运算及括号的数学表达式,并利用JavaScript内置的eval函数来求解表达式的值。

题目原文:
Implement a basic calculator to evaluate a simple expression string.
The expression string may contain open ( and closing parentheses ), the plus + or minus sign -, non-negative integers and empty spaces .
You may assume that the given expression is always valid.
题目大意:
计算一个表达式的值,包括+,-,和括号还有空格。
题目分析:
这回用eval水过去。
源码:(language:JavaScript)

var calculate = function(s) {
    return eval(s)
};

成绩:
140ms,beats 78.13%,众数176ms,184ms,9.38%

行 3278: 11-02 14:48:13.375 1707 5019 D OplusStartingWindowManager: we don't revise window flags for system activity :ActivityRecord{90637794 u0 com.coloros.calculator/com.android.calculator2.Calculator t19091} 行 3281: 11-02 14:48:13.375 1707 5019 D OplusStartingWindowManager: allowUseSnapshot ==> record =:ActivityRecord{90637794 u0 com.coloros.calculator/com.android.calculator2.Calculator t19091},newTask =:true,taskSwitch =:true,processRunning =:true,activityCreated =:false 行 3285: 11-02 14:48:13.376 1707 5019 D OplusStartingWindowManager: updateStartingRecords activity=ActivityRecord{90637794 u0 com.coloros.calculator/com.android.calculator2.Calculator t19091}, isAdd=true, size=156, call by:com.android.server.wm.OplusAppQuickStartController.attachExStartingSurfaceInner:811 com.android.server.wm.OplusAppQuickStartController.attachExStartingSurface:767 com.android.server.wm.QuickStartController.attachExStartingSurface:113 com.android.server.wm.ActivityRecordExtImpl.attachExStartingSurface:3549 com.android.server.wm.ActivityRecord.addStartingWindow:2843 行 3344: 11-02 14:48:13.389 1707 5019 D OplusStartingWindowManager: hookAddStartingWindow: not support forcePreview! ActivityRecord{90637794 u0 com.coloros.calculator/com.android.calculator2.Calculator t19091} 行 3345: 11-02 14:48:13.389 1707 5019 D OplusStartingWindowManager: hasSplashWindowFlag: hasFlag=false, mStartingWindowFlags=0x0 行 3346: 11-02 14:48:13.389 1707 5019 D OplusStartingWindowManager: hookAddStartingWindow: not supportSnapshotPreview! 行 3349: 11-02 14:48:13.391 1707 5019 D OplusStartingWindowManager: updateStartingRecords activity=ActivityRecord{90637794 u0 com.coloros.calculator/com.android.calculator2.Calculator t19091}, isAdd=true, size=156, call by:com.android.server.wm.ActivityRecordExtImpl.updateStartingRecords:3219 com.android.server.wm.ActivityRecord.scheduleAddStartingWindow:2906 com.android.server.wm.ActivityRecord.addStartingWindow:2851 com.android.server.wm.ActivityRecord.showStartingWindow:8911 com.android.server.wm.ActivityRecord.showStartingWindow:8806 行 3378: 11-02 14:48:13.409 1707 5019 D OplusStartingWindowManager: reviseWindowFlagsForStarting ar =:ActivityRecord{90637794 u0 com.coloros.calculator/com.android.calculator2.Calculator t19091}, activityCreated =:false, RUS version:20251009 行 3379: 11-02 14:48:13.409 1707 5019 D OplusStartingWindowManager: hasSplashWindowFlag: hasFlag=false, mStartingWindowFlags=0x0 行 3380: 11-02 14:48:13.409 1707 5019 D OplusStartingWindowManager: we don't revise window flags for system activity :ActivityRecord{90637794 u0 com.coloros.calculator/com.android.calculator2.Calculator t19091} 行 3402: 11-02 14:48:13.410 1707 5019 D OplusStartingWindowManager: notifyNoStartingWindow: act=com.coloros.calculator/com.android.calculator2.Calculator, code=2304 行 3734: 11-02 14:48:13.502 1707 4669 D OplusStartingWindowManager: addStartingBackColorLayerIfNeed no need, win:Window{5d8a833 u0 Splash Screen com.coloros.calculator},isStartingBackColorLayerAdded:false 行 3769: 11-02 14:48:13.568 1707 1749 D OplusStartingWindowManager: removeStartingBackColorLayerIfNeed no need, win:Window{5d8a833 u0 Splash Screen com.coloros.calculator} 行 3785: 11-02 14:48:13.576 1707 4723 D OplusStartingWindowManager: isLayerMatchToStartingWindow packageClassName:com.katanlabs.bubblepop/com.google.firebase.MessagingUnityPlayerActivity forceWaitLayer:null 行 3786: 11-02 14:48:13.576 1707 4723 D OplusStartingWindowManager: isLayerMatchToStartingWindow , activityHasSurfaceView:false, isLayerMatchToRecord:false, isSurfaceViewLayer:false, layerName:Splash Screen com.coloros.calculator#1437878, mStartingRecords:[UniqueWeakReference@99eeeac[null], UniqueWeakReference@d705209[null], UniqueWeakReference@93d9af5[null], UniqueWeakReference@69d33dd[null], UniqueWeakReference@8832ef5[null], UniqueWeakReference@aa96ca2[null], UniqueWeakReference@79425c0[null], UniqueWeakReference@5c708b3[null], UniqueWeakReference@df43acf[null], UniqueWeakReference@f751d09[null], UniqueWeakReference@adf5f7e[null], UniqueWeakReference@649f25f[null], UniqueWeakReference@a6ddef6[null], UniqueWeakReference@497f1bf[null], UniqueWeakReference@716dae7[null], UniqueWeakReference@ca733cc[null], UniqueWeakReference@427fe74[null], UniqueWeakReference@97b337c[null], UniqueWeakReference@ff7e429[null], UniqueWeakReference@fc4d12d[null], UniqueWeakReference@f170cd2[null], UniqueWeakReference@2223634[null], UniqueWeakReference@ecc6a7e[null], UniqueWeakReference@f72df2e[null], UniqueWeakReference@9b2e991[null], UniqueWeakReference@52aa757[null], UniqueWeakReference@316726[null], UniqueWeakReference@fee5d65[null], UniqueWeakReference@40a48cc[null], UniqueWeakReference@102cbb0[null], UniqueWeakReference@2b313ee[null], UniqueWeakReference@e3bde1f[null], UniqueWeakReference@8dfbfbf[null], UniqueWeakReference@1def358[null], UniqueWeakReference@1c9017[null], UniqueWeakReference@67bcb4a[null], UniqueWeakReference@86e82c6[null], UniqueWeakReference@6b65cd6[null], UniqueWeakReference@e1266cf[null], UniqueWeakReference@5e8da71[null], UniqueWeakReference@7faddc5[null], UniqueWeakReference@b41e182[null], UniqueWeakReference@a32dc4b[null], UniqueWeakReference@a5a59b1[null], UniqueWeakReference@5be32b9[null], UniqueWeakReference@f49b2bc[null], UniqueWeakReference@1c80d84[null], UniqueWeakReference@d625eff[null], UniqueWeakReference@c3c778e[null], UniqueWeakReference@be5a3d3[null], UniqueWeakReference@1606e32[null ... 行 4661: 11-02 14:48:14.210 1707 4508 D OplusStartingWindowManager: addStartingBackColorLayerIfNeed no need, win:Window{5c5b9c5 u0 com.coloros.calculator/com.android.calculator2.Calculator},isStartingBackColorLayerAdded:false 行 5242: 11-02 14:48:14.561 1707 1749 D OplusStartingWindowManager: interceptRemoveStartingWindow: packageName=com.coloros.calculator, componentName=com.coloros.calculator/com.android.calculator2.Calculator, isSnapshot=false, startingSurfaceRunnable=null, isDrawCompleted=false, hasSurfaceView=false, inTransition=false 行 5244: 11-02 14:48:14.561 1707 1749 D OplusStartingWindowManager: hasSplashWindowFlag: hasFlag=false, mStartingWindowFlags=0x0 行 5245: 11-02 14:48:14.561 1707 1749 D OplusStartingWindowManager: interceptRemoveStartingWindow: hasSplashWindowFlag() return false for activity=ActivityRecord{90637794 u0 com.coloros.calculator/com.android.calculator2.Calculator t19091} 行 5286: 11-02 14:48:14.586 1707 4508 D OplusStartingWindowManager: hasRemoveStartingWindowImmediatelyFlag: has=false, mStartingWindowFlags=0x0 行 5287: 11-02 14:48:14.586 1707 4508 D OplusStartingWindowManager: hasSplashWindowFlag: hasFlag=false, mStartingWindowFlags=0x0 行 5289: 11-02 14:48:14.586 1707 4508 D OplusStartingWindowManager: createStartingWindowExitAnimationForPackage duration =:0,windowState =:Window{5d8a833 u0 Splash Screen com.coloros.calculator} 行 5364: 11-02 14:48:14.607 1707 1749 D OplusStartingWindowManager: supportWindowPreviewWhenStartingWindowExit Entry =: StartingWindowAttributeCache Entry : [ windowPreviewType : 0,windowSnapshotPreviewToken : null,supportSnapshotPreview : false,supportTitlePreview : false,startingWindowTitle : null ],spend time =: 24077 行 5365: 11-02 14:48:14.607 1707 1749 D OplusStartingWindowManager: putSnapshotForTaskPreview: mRequestStoreAppTokenSnapshot=false, mAllowAppSnapshot=true, activity=ActivityRecord{90637794 u0 com.coloros.calculator/com.android.calculator2.Calculator t19091} 行 5465: 11-02 14:48:14.630 1707 6817 D OplusStartingWindowManager: skip remove starting window for activity = ActivityRecord{9972313 u0 com.android.launcher/.Launcher t19232} ,ar != topActivityContainsStartingWindow on activityStopped 行 5469: 11-02 14:48:14.631 1707 6817 D OplusStartingWindowManager: updateStartingRecords activity=ActivityRecord{9972313 u0 com.android.launcher/.Launcher t19232}, isAdd=false, size=156, call by:com.android.server.wm.OplusStartingWindowManager.onActivityStopped:2920 com.android.server.wm.ActivityRecordExtImpl.onActivityStopped:1826 com.android.server.wm.ActivityRecord.activityStopped:7991 com.android.server.wm.ActivityClientController.activityStopped:306 android.app.IActivityClientController$Stub.onTransact:710 行 6443: 11-02 14:48:15.436 1707 4388 D OplusStartingWindowManager: addStartingBackColorLayerIfNeed no need, win:Window{3dd44f2 u0 Toast},isStartingBackColorLayerAdded:false
11-04
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值