var minFlipsMonoIncr = function(s) {
const n=s.length
let dp0=0,dp1=0
for(let i=0
const c=s[i]
let dp0new=dp0,dp1new=Math.min(dp0,dp1)
if(c==='1'){
dp0new++
}else{
dp1new++
}
dp0=dp0new
dp1=dp1new
}
return Math.min(dp0,dp1)
}
var increasingBST = function(root) {
let vals=getVals(root)
let dummyNode=new TreeNode(-1)
let cur=dummyNode
for(let i of vals){
cur.right=new TreeNode(i)
cur=cur.right
}
return dummyNode.right
};
const getVals=(root)=>{
let res=[]
const dfs=(node)=>{
if(!node){
return
}
dfs(node.left)
res.push(node.val)
dfs(node.right)
}
dfs(root)
return res
}
var inorderSuccessor = function(root,p) {
let cur=root
let res=null
while(cur){
if(cur.val>p.val){
res=cur
cur=cur.left
}else{
cur=cur.right
}
}
return res
}
var convertBST = function(root) {
let res=[]
const dfs=(node)=>{
if(!node){
return
}
dfs(node.right)
res.push(node.val)
node.val=getSum(res)
dfs(node.left)
}
dfs(root)
return root
};
const getSum=(arr)=>{
return arr.reduce((a,b)=>a+b,0)
}