labuladong / basic-challenge

200 stars 23 forks source link

已结束 #347

Closed labuladong closed 1 year ago

labuladong commented 1 year ago

本期打卡已结算完成。报名最新一期的打卡活动 点这里

dh0072 commented 1 year ago

Q48. Rotate Image https://leetcode.com/problems/rotate-image/discuss/3864950/Java-Solution

Reset0808 commented 1 year ago

https://leetcode.cn/problems/rotate-image/solutions/2373753/xuan-zhuan-ju-zhen-by-2ba4zmutle-307t/

jojoss commented 1 year ago

[59. Spiral Matrix II] https://leetcode.com/problems/spiral-matrix-ii/solutions/3864985/4-boundaries/

wangyin717 commented 1 year ago

[48]旋转图像 https://leetcode.cn/problems/rotate-image/solutions/2373748/48-xuan-zhuan-tu-xiang-by-wangyin717-ji75/ [54]螺旋矩阵 https://leetcode.cn/problems/spiral-matrix/solutions/2373794/54-luo-xuan-ju-zhen-by-wangyin717-h0xg/ [59]螺旋矩阵 II https://leetcode.cn/problems/spiral-matrix-ii/solutions/2373816/59-luo-xuan-ju-zhen-ii-by-wangyin717-ojv3/

ImmersiveAngela commented 1 year ago

54.螺旋数组的遍历 https://leetcode.cn/problems/spiral-matrix/solutions/2373841/54luo-xuan-shu-zu-de-bian-li-by-immersiv-o9f8/

Chao200 commented 1 year ago

48: https://leetcode.cn/problems/rotate-image/solutions/2373788/solution48-xuan-zhuan-tu-xiang-by-xiaoch-r3p2/

54: https://leetcode.cn/problems/spiral-matrix/solutions/2373802/solution54-luo-xuan-ju-zhen-by-xiaochao2-wctk/

59: https://leetcode.cn/problems/spiral-matrix-ii/solutions/2373821/solution59-luo-xuan-ju-zhen-ii-by-xiaoch-odhm/

151: https://leetcode.cn/problems/reverse-words-in-a-string/solutions/2373866/solution151-fan-zhuan-zi-fu-chuan-zhong-ledrz/

zexianw12 commented 1 year ago

Q48 https://leetcode.cn/problems/rotate-image/solutions/2373884/shun-shi-zhen-xuan-zhuan-tu-xiang-by-vve-mpg4/

chen-huanxin commented 1 year ago

Q48:https://leetcode.cn/problems/rotate-image/solutions/2373902/cppdui-cheng-fan-zhuan-48xuan-zhuan-ju-z-dy10/

ghost commented 1 year ago

https://leetcode.cn/problems/rotate-image/solution/xuan-zhuan-tu-xiang-by-alan-aa-rla8/ https://leetcode.cn/problems/spiral-matrix/solutions/2373921/luo-xuan-ju-zhen-by-alan-aa-q5cd/

GodisinHisHeaven commented 1 year ago

https://leetcode.com/problems/reverse-words-in-a-string/solutions/3865361/python3-solution/

Bamoon622 commented 1 year ago

https://leetcode.com/problems/spiral-matrix/solutions/3865544/shrinking-boundaries/

wangbingran163 commented 1 year ago

https://leetcode.cn/problems/shun-shi-zhen-da-yin-ju-zhen-lcof/solutions/2374014/shun-shi-zhen-da-yin-ju-zhen-by-dao-yan-nlyrz/

hxingjie commented 1 year ago

48.https://leetcode.cn/problems/rotate-image/solutions/2374102/xuan-zhuan-tu-xiang-by-betodea-xg5p/ 54.https://leetcode.cn/problems/spiral-matrix/solutions/2374125/luo-xuan-ju-zhen-by-betodea-deks/ 59.https://leetcode.cn/problems/spiral-matrix-ii/solutions/2374172/luo-xuan-ju-zhen-ii-by-betodea-sstt/

sdyin commented 1 year ago

48.旋转图像 https://leetcode.cn/problems/rotate-image/solutions/2374253/48-xuan-zhuan-tu-xiang-ti-jie-by-sdyin-6vgm/

Sadwy commented 1 year ago

LC48. https://leetcode.com/problems/rotate-image/solutions/3866309/topic/

AlanKang98 commented 1 year ago

https://leetcode.cn/problems/rotate-image/solutions/2374298/xian-dui-jiao-xian-fan-zhuan-zai-zuo-you-crzg/

jiuxi521 commented 1 year ago

https://leetcode.cn/problems/reverse-words-in-a-string/solutions/2374306/fan-zhuan-xue-xi-de-api-by-lean-in-c-ozkb/

Abbyyuan01 commented 1 year ago

https://leetcode.cn/problems/rotate-image/solutions/2374390/xuan-zhuan-tu-xiang-by-abbyyuan01-3qkq/

Adrian0999 commented 1 year ago

https://leetcode.com/problems/rotate-image/solutions/3866800/100-speed-solution/

ConnieLuksc commented 1 year ago

https://leetcode.com/problems/rotate-image/solutions/3866864/solve-rotate-image-in-python/

txhj1996 commented 1 year ago

https://leetcode.cn/problems/rotate-image/solution/xuan-zhuan-tu-xiang-by-6ifted-vvrightj26-r4ok/

KenanHuang commented 1 year ago

https://leetcode.cn/problems/rotate-image/solutions/2374457/rotate-img-by-qq540453543-cqzm/

guabigwind commented 1 year ago

螺旋矩阵 https://leetcode.cn/problems/spiral-matrix/solutions/2374475/luo-xuan-ju-zhen-by-guabigwind-ff1q/

Jingzhenzxz commented 1 year ago

https://leetcode.cn/problems/reverse-words-in-a-string/solutions/2374494/cong-hou-wang-qian-bian-li-li-yong-strin-iu6j/ 参考 https://leetcode.cn/problems/reverse-words-in-a-string/solutions/194450/fan-zhuan-zi-fu-chuan-li-de-dan-ci-by-leetcode-sol/comments/1547002

从后往前遍历,利用 string 的 append 方法,在遍历中把单词依次拼接在一起。

class Solution {
    public String reverseWords(String s) {
        // 每个单词的开始和结束索引(左闭右开)
        int start;
        int end;
        StringBuilder sb = new StringBuilder();
        for (int i = s.length() - 1; i >= 0; i--) {
            // 跳过空格。这里不能用 while {i--},因为 for 循环里还有一个
            // i--,下次 for 循环执行到这里会减两次 i。
            if (s.charAt(i) == ' ') {
                continue;
            }
            // 找到结束索引,此时 charAt(i) 不是空格,charAt(i+1) 是
            end = i + 1;

            // 跳过空格,这里不能用
            // if continue
            // 因为 continue 后会先执行上面的代码,我们希望遇到非空字符
            // 直接左移,不要做前面的操作
            while (i >= 0 && s.charAt(i) != ' ') {
                i--;
            }
            // 找到开始索引,此时 charAt(i) 是空格,charAt(i+1) 不是
            start = i + 1;

            // 将每个单词按开始结束索引赋值到 StringBuilder,用
            // sb.append(s.substring(start, end));
            // 也可以,但是会占用更多内存
            for (int j = start; j < end; j++) {
                sb.append(s.charAt(j));
            }
            // 每个单词之间都要有一个空格
            sb.append(' ');
        }
        // 删掉最后一个多余的空格
        sb.deleteCharAt(sb.length() - 1);
        return sb.toString();
    }
}
wusidong commented 1 year ago

https://leetcode.cn/problems/rotate-image/solutions/2374632/xuan-zhuan-tu-xiang-by-gei-wei-lai-de-zi-5a8e/

azDev120 commented 1 year ago

48: https://leetcode.com/problems/rotate-image/solutions/3867625/java-simple-trick/

ShaodongGu commented 1 year ago

Q48: https://leetcode.com/problems/rotate-image/solutions/3864570/think-outside-the-box/

Catboss1999 commented 1 year ago

https://leetcode.cn/problems/rotate-image/solutions/2374678/yong-zuo-you-zhi-zhen-jing-xiang-fan-zhu-bn7r/

KarlZhu-SE commented 1 year ago

SC: O(1) https://leetcode.com/problems/reverse-words-in-a-string/solutions/3867825/reverse-string-then-reverse-words/

Susan19996 commented 1 year ago

151 https://leetcode.com/problems/reverse-words-in-a-string/ 48 https://leetcode.com/problems/rotate-image/

lilangpinglee commented 1 year ago

https://leetcode.cn/problems/rotate-image/solutions/2374777/rotate-image-by-qui2zical-hypatianad-aclx/

vanessacz commented 1 year ago
  1. Rotate Image: https://leetcode.com/problems/rotate-image/solutions/3869089/java-0ms-solution/
Cathy830 commented 1 year ago

https://leetcode.com/problems/rotate-image/solutions/3869113/rotate-image-in-java/

macksonyli21826 commented 1 year ago

https://leetcode.cn/problems/rotate-image/solutions/2374843/problem-48-xuan-zhuan-tu-xiang-by-hachi-hdlso/

yayideng commented 1 year ago

https://leetcode.cn/problems/rotate-image/solutions/2374844/pythonti-jie-by-7aughing-i3habhasyh-7d9c/

PINKDDDD commented 1 year ago

https://leetcode.com/problems/spiral-matrix-ii/solutions/3869481/spiral-matrix-ii/

LexieZhou commented 1 year ago

https://leetcode.com/problems/rotate-image/solutions/3870808/java-smart-method-to-traverse-matrix/

skyc26 commented 1 year ago

https://leetcode.cn/problems/rotate-image/solutions/2375534/48-xuan-zhuan-tu-xiang-dui-cheng-fan-zhu-729j/

tonyzhu163 commented 1 year ago

https://leetcode.com/problems/rotate-image/discuss/3918192/LC-48-Python

Xiaolin8991 commented 1 year ago

https://leetcode.cn/problems/spiral-matrix-ii/solutions/2375622/python3-by-xiao-lin-mz-uvbs/

lidebin11 commented 1 year ago

048.旋转图像 https://leetcode.cn/problems/rotate-image/solutions/2375643/python-xuan-zhuan-tu-xiang-xian-zhuan-zh-lrjn/

DannyT70 commented 1 year ago

https://leetcode.cn/problems/rotate-image/solutions/2375660/er-wei-shu-zu-bian-li-1-by-sleepy-shawff-w8br/

cs-gavin-huang commented 1 year ago

https://leetcode.com/problems/rotate-image/solutions/3871619/rotate-image/

javaSnacks commented 1 year ago

48、 https://leetcode.cn/problems/rotate-image/solutions/2375839/48-xuan-zhuan-tu-xiang-by-su-su-shu-shu-4te5/

CarolSSS commented 1 year ago

https://leetcode.com/problems/spiral-matrix/solutions/3872374/set-boundary-for-l-r-u-d/

imzhuting commented 1 year ago

https://leetcode.cn/problems/rotate-image/solutions/2376010/xuan-zhuan-tu-xiang-by-emilia-8-n352/

SuperChaoChao666 commented 1 year ago

二维数组的花式遍历-旋转图像 https://leetcode.cn/problems/rotate-image/solution/er-wei-shu-zu-de-hua-shi-bian-li-zhuan-t-2ypf/

uhu-11 commented 1 year ago

https://leetcode.cn/problems/rotate-image/solutions/2376061/xuan-zhuan-tu-xiang-yuan-di-xiu-gai-shu-3fw0c/

guaZong commented 1 year ago

https://leetcode.cn/problems/rotate-image/solutions/2376065/xuan-zhuan-tu-xiang-by-gua-xi-xi-8-573u/

sukhfskehwefisfsenkfn commented 1 year ago

https://leetcode.cn/problems/spiral-matrix-ii/solutions/2376081/jie-jue-fang-fa-by-bao-tu-6-a9yd/