classSolution{publicStringreplaceSpace(String s){int len = s.length();StringBuffer str =newStringBuffer();for(int i =0; i < len ; i++){if(s.charAt(i)==' ') str.append("%20");//遇到空格就在尾部拼接%20else str.append(s.charAt(i));//遇到字符就在尾部正常拼接字符}return str.toString();}}
方法二:双指针做法
classSolution{publicStringreplaceSpace(String s){int len = s.length();StringBuffer str =newStringBuffer(s);if( len ==0)return"";for(int i =0; i< len ; i++)if(s.charAt(i)==' ') str.append(" ");//扩充空间,空格数量2倍String string = str.toString();char[] strs = string.toCharArray();int left = s.length()-1;int right = str.length()-1;while(left >=0){if(str.charAt(left)==' '){strs[right--]='0';strs[right--]='2';strs[right]='%';}else strs[right]= strs[left];right--;left--;}returnnewString(strs);}}
文章目录 1.摘要2.算法2.1 Cross-attention in text-conditioned Diffusion Models2.2 Controlling the Cross-attentionWord SwapAdding a New PhraseAttention Re–weighting 3.应用Text-Only Localized EditingGlobal editingFader Control using Attention Re-weightingRea…
利用二维数组储存高精长整型 题目解题思路问题解决代码实现总结反思 题目
luogu P2437 蜜蜂路线
解题思路 最初只觉得是一道很简单的递推 先考虑从第一个点出发的情况,对于第 k ( k ≥ 3 ) k (k≥3) k(k≥3)个点,路线数表示如下: a [ k …